Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm creating a Google Analytics Dashboard. In there the Start Date & End Date is inserted using JQuery Date Picker. I am inserting dates in the mm/dd/yyyy format. But I want to submit them in the yyyy-mm-dd. I have used the following code to do that.

JavaScript
$("#to_date, #from_date").datepicker({maxDate: new Date(),dateFormat:'yyyy-mm-dd'});


At there the date inserted as 20142014-07-01 not as 2014-07-01. So I changed the format to yy-mm-dd. After that I got an error when after submit this date saying

" **{"error":{"errors":[{"domain":"global","reason":"invalidParameter","message":"Invalid value ' 2014-07-24 '. Values must match the following regular expression: '[0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo)'","locationType":"parameter","location":"end-date"},{"domain":"global","reason":"invalidParameter","message":"Invalid value ' 2014-07-01 '. Values must match the following regular expression: '[0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo)'","locationType":"parameter","location":"start-date"}],"code":400,"message":"Invalid value ' 2014-07-24 '. Values must match the following regular expression: '[0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo)'"}}** "

I am using JavaScript.

I cannot understand what should I do. Can anyone show me how to do this?

Thnaks & regards,
Chiranthaka
Posted

1 solution

The format string for the datepicker widget uses yy to represent the four-digit year. By setting the format to yyyy-mm-dd, you've told it to put the four-digit year followed by the four-digit year, which is why you're getting 20142014.

Change the date format to yy-mm-dd and you should get the correct output.

http://api.jqueryui.com/datepicker/#utility-formatDate[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900