[RESOLVED]date formt isue c# and jquery

hello, I have a db with the  data attribute

and i’m using jquery date picker to insert date

in my computer I have no problem choosing and inserting but all users has report error: must be a date format

How can I fix it and what  wrong here ? 

code

in my class :

[DisplayFormat(DataFormatString = "{0:dd MMM }")]
           
public DateTime WeekFrom { get; set; }
        
[DisplayFormat(DataFormatString = "{0:dd MMM }")]

public DateTime? Until { get; set; }
 in my script 

$(function () {
    $(".date-picker").datepicker({ dateFormat: 'dd-mm-yy' });
})

my Sql look like this 
WeekForm (datetime not null)
Until(datetimee,null)

how  can I fix it and what is wrong  here?

Based on the current format you are using, you’ll likely need to change the format of your DatePicker to match :

$(".date-picker").datepicker({ dateFormat: 'dd MM' });

Additionally, another problem is that the ‘mm’ value you are using in your DateFormat actually denotes minutes instead of months. If you wanted to use months (which is likely), you’ll instead want to use the capitalized ‘MM’ instead :

$(".date-picker").datepicker({ dateFormat: 'dd-MM-yy' });

This should help to ensure that the formats coincide between your actual DisplayFormat attributes and the value contained in your DatePicker. Additionally, if you are using Chrome or the jQuery.validate library, you might want to look into
this known issue regarding DateTime objects being parsed or validated improperly.

Rion Williams

Based on the current format you are using, you’ll likely need to change the format of your DatePicker to match :

$(".date-picker").datepicker({ dateFormat: 'dd MM' });

Additionally, another problem is that the ‘mm’ value you are using in your DateFormat actually denotes minutes instead of months. If you wanted to use months (which is likely), you’ll instead want to use the capitalized ‘MM’ instead :

$(".date-picker").datepicker({ dateFormat: 'dd-MM-yy' });

This should help to ensure that the formats coincide between your actual DisplayFormat attributes and the value contained in your DatePicker. Additionally, if you are using Chrome or the jQuery.validate library, you might want to look into
this known issue regarding DateTime objects being parsed or validated improperly.

hello Rion, thanks,

using :

$(function () {
    $(".date-picker").datepicker({ dateFormat: 'dd-MM-yy' });
})
i'm getting in my page a date that look like this :"30-September-2014" and error MSG :" The field must be a date"

Oops. 

I appeared to get my ASP.NET and jQuery code mixed up. The lowercase format should be fine : 

$(function () {
    $(".date-picker").datepicker({ dateFormat: 'dd-mm-yy' });
})

Is there any chance that you are using any kind of validation-based scripts (like jQuery.validate)? Or is the error message you are receiving coming from the actual server-side code?

A

Rion Williams

Oops. 

I appeared to get my ASP.NET and jQuery code mixed up. The lowercase format should be fine : 

$(function () {
    $(".date-picker").datepicker({ dateFormat: 'dd-mm-yy' });
})

Is there any chance that you are using any kind of validation-based scripts (like jQuery.validate)? Or is the error message you are receiving coming from the actual server-side code?

thanks Rion for your time and help.  ,

it look fine on my side . i’ll check with users  to find out.

Problem fix . thanks Rion.

and yes this is Jquery validator.

Leave a Reply