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
Regional Settings, have you checked? in production. abs.
– Thiago Loureiro
Have you tried dateFormat: 'dd/MM/yyyy' ? and in the row var string = jQuery.datepicker.formatDate('dd-MM-yyyy', date);
– Evandro
What database are you using?
– Fernando
I made a Fiddle and your code seems to be ok!
– Marconi
@Evandro change the
dateFormat
for what you suggested puts the date as27/November/20172017
in the saw.– Vinicius
@Fernando use SQL Server
– Vinicius
@Marconi yes everything is working well, my problem is this inversion of day and month while saving in the database, the display is okay
– Vinicius
Are you using Asp net mvc? The mvc receives in mm-dd-yyyy format
– Marco Antonio Quintal
@Marcoantonioquintal yes use MVC, the date is correctly passed as
dd/mm/yy
– Vinicius
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 this4 Dec 2017
, when I useToString("d MMM yyyy")
– Vinicius
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)]
– Marco Antonio Quintal