leelakrishnamoturu Posted September 27, 2010 Share Posted September 27, 2010 I got a problem while formatting date in java scriptThe scenario is i will enter start date and end date in a form and i need to validate these date and the validation rule is end date should be greater than start dateWhen i am trying in US locale it working fine,but when i am trying in Australia locale with specific values Start Date is 24/09/2010 End date is 01/11/2010The validation is failedI am using Date.parse()/Date.parse().UTC() function in javascript to convert those date into millisecond and then later checking them which is biggerCould you find the solution for it Link to comment Share on other sites More sharing options...
ShadowMage Posted September 27, 2010 Share Posted September 27, 2010 I think you can just do a direct comparison. ie:var startDate = new Date('24/09/2010');var endDate = new Date('01/11/2010');if (startDate > endDate) {//...Error}I haven't tested it though. Link to comment Share on other sites More sharing options...
aspnetguy Posted September 27, 2010 Share Posted September 27, 2010 Yes that should work. You can also see this thread http://stackoverflow.com/questions/492994/...with-javascript for some functions that convert input and compare dates. Link to comment Share on other sites More sharing options...
leelakrishnamoturu Posted September 28, 2010 Author Share Posted September 28, 2010 Hi, Thanks for the reply but i need to use the date with timestamp also when i used that same code it is giving me a wrong date i.e for 24/09/2010 it is giving me 05/06/2012 Link to comment Share on other sites More sharing options...
ShadowMage Posted September 28, 2010 Share Posted September 28, 2010 ...also when i used that same code it is giving me a wrong date i.e for 24/09/2010 it is giving me 05/06/2012Yea, forgot about that. You need to put it in mm/dd/yyyy format. In other words, new Date('09/24/2010') Link to comment Share on other sites More sharing options...
leelakrishnamoturu Posted September 28, 2010 Author Share Posted September 28, 2010 But i cant use hard coding actually depending upon locale i need to format But if we take US local it is in MMM DD,YY formatIn Date base it will be stored in DD/MM/YYYY Link to comment Share on other sites More sharing options...
jeffman Posted September 28, 2010 Share Posted September 28, 2010 If you know how the data base formats the date, and the format is consistent for every item, then you can use built-in string functions to parse the date into the format JavaScript expects. Link to comment Share on other sites More sharing options...
ShadowMage Posted September 28, 2010 Share Posted September 28, 2010 If you know how the data base formats the date, and the format is consistent for every item, then you can use built-in string functions to parse the date into the format JavaScript expects.For example, use split() to create an array of the pieces and then reassemble it into a string that JavaScript will understand. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.