Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
heyy..
I have a date ,that give the current day, month and 5+ year , but when I change the system date , the list that contains the date get invaild..


here is my javascipt code -

C#
var param1 = new Date();
              var param2 = param1.getDate() + '/' + (param1.getMonth() + 1) + '/' + (param1.getFullYear() + 5);



IN my controller -
Iam getting a list ,If I change the system datetime format, then the element(datetime) in the list get invalid(display : 01/01/0001).


Any idea?
Posted
Comments
Sampath Lokuge 18-Jan-14 6:52am    
Can you show the code snippet for your action method ?
Are you using datepicker control or what ?
Richard MacCutchan 18-Jan-14 7:43am    
I just tried your code at http://www.w3schools.com/js/tryit.asp?filename=tryjsref_date and it shows the correct result. The format of the system datetime should not affect this, since dates and times are objects, not formatted strings.

You can use date format plugin for format the date according to your requirement.

jquery-dateFormat

$.format.date(param1, 'dd/MM/yyyy')
 
Share this answer
 
Hello
in c# Datetime is totally dependent of culture information of machine or server datetime if you change your datetime format it automatically change thats why give error.
for solving this you can send date in mm/dd/yyyy format and it is unique format for sql server you can easy enter it on to the database.


when you display it please change it into dd/mm/yyyy or your requirement.
C#
var param1 = new Date();
              var param2 = (param1.getMonth() + 1) + '/' +  param1.getDate() + '/' + (param1.getFullYear() + 5);




i hope your problem will solve if not please comment.
 
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