Month and day reversed when saving to database

Asked

Viewed 184 times

0

I’m using datepicker of jqueryUI to choose the date in a calendar, the problem is, if I choose 04/12/2017 is saved at the bank 12/04/2017.

datepicker:

$('#schedulingCalendar').datepicker({
                dateFormat: 'dd/mm/yy',
                beforeShowDay: function(date){
                    var string = jQuery.datepicker.formatDate('d-m-yy', date);
                    return [ $.inArray(string, arrayDaysToshow) >= 0 ]
                },
                onSelect: function(){
                    $('#schedulingCalendar').removeClass('input-validation-error');
                    $('#messageSchedulingDate').hide();
                    $('#messageCheckDate').hide();
                },
                onClose: function(){
                    $("#panelCalendar").animate({'height': '100%'}, 150);
                }
            });

If I change the dateFormat for yy/mm/dd, saved correctly on the bench, remembering that this problem occurs only in production, in debug works normal.

OBS: by debugging the code until the SaveChanges (Repository use) the date is correct (04/12/2017) but to consolidate in the bank 12/04/2017

EDIT another curious thing, I’m using the ToString("d MMM yyyy") to display the date after saving, debug displays so for example 4 dez 2017 and on the server it displays like this 4 Dec 2017

  • 1

    Regional Settings, have you checked? in production. abs.

  • Have you tried dateFormat: 'dd/MM/yyyy' ? and in the row var string = jQuery.datepicker.formatDate('dd-MM-yyyy', date);

  • What database are you using?

  • I made a Fiddle and your code seems to be ok!

  • @Evandro change the dateFormat for what you suggested puts the date as 27/November/20172017 in the saw.

  • @Fernando use SQL Server

  • @Marconi yes everything is working well, my problem is this inversion of day and month while saving in the database, the display is okay

  • Are you using Asp net mvc? The mvc receives in mm-dd-yyyy format

  • @Marcoantonioquintal yes use MVC, the date is correctly passed as dd/mm/yy

  • another thing I’m finding strange is in development display the date in Portuguese like this 4 dez 2017 and on the server display in English like this 4 Dec 2017, when I use ToString("d MMM yyyy")

  • But the Asp net mvc will get it wrong because it waits mm-dd-yyyy you will have to configure to get it correctly. Try placing the attribute [Datatype(Datatype.Date), Displayformat(Dataformatstring = "{0:dd.MM.yyyy}", Applyformatineditmode = true)]

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.