0

I am passing Date having format('dd/mm/yyyy') from jquery to C# using Page Method. When i pass date 31/07/2014 to PageMethod, it gives me error 31/07/2014 is not a valid value for DateTime. Here is my Code..

 var dto = { 
            'StudentList': StudentList, 
            'StudentFeeList': StudentFeeDetail, 
            'StartingDate': $('#txtStartingDate').val(), 
            'ClosingDate': $('#txtEndingDate').val() 
          };

this DTO is passed to PageMethod. I am saving data at this time.

While retrieving Date from DataBase i have converted it like this.

convertDate = function (jsonDate) {
   var date = new Date(parseInt(jsonDate.substr(6)));
   return date.format("dd/mm/yyyy");
},

Any Help.. Thanks.

1
  • 1
    Please post the code you are using to retrieve and send this date calue. Commented Mar 5, 2014 at 10:24

1 Answer 1

1

This is because when converting its taking it as mm/dd/yyyy as per your system date time, whenever you post/convert use Universal format i.e. YYYY-MM-DD

Using universal format is universally accepted format and will not give any issues when converting IT or TO to any format needed.

Sign up to request clarification or add additional context in comments.

7 Comments

Ok try to post something like 07/07/2014 and see if it still gives issue.
No if day value is equal or less than month, then its ok.
Yes this is because of same reason I mentioned, try to send it in universal format and you will be good.
StartDate=01/08/2013 and ClosingDate=31/07/2014, for StartDate its ok, but on closingDate its give me error.
This is because its converting it into MM/DD/YYY and taking MM as 31, as this is not valid thats why its giving error.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.