I have date field,Onclick on date feild,i have to calculate the date with the current date .if entered date is one month older than today date.I have to popup amessage saying date is olderthan 1 month.
Date format is "yyyy-MM-dd".i want to compare with date "1984-03-20" to today date "2011-04-14".it should return number of months.
Any hints on this. Regards,
Chaitu
Maybe this could help to you:
http://www.ozzu.com/programming-forum/javascript-date-comparison-t46552.html
See this discussion it has demos for getting date difference in javascript. Also this is a good example: javascript-date-difference-calculation it shows how to get difference in month, in week or in year.
You can read up about js Date object to see what formats it can accept.
A blog about JS Date formats
The easiest way to compare dates in javascript is to first convert it to a Date object and then compare these date-objects.
Below you find an object with below function:
You can do something like that:
This would work. Pass the value of the field to dateString onclick and the code will determine whether the date is older than 1 month or not.
Demo: http://jsfiddle.net/cw4vb/