I'm not going to write your code, but in .NET you can use ToString
to specify a date format, TryParse
to get a date out of a string. And AddDays
, AddMonths
etc to manipulate a date.
In javascript, there's no simple way to format output, but you can use getMonth
etc to prompt the individual values and concatenate a string from that. You can use a combination of getDate
and setDate
to manipulate dates. It automatically corrects for new months, i.e. if you run myDate.setDate( myDate.getDate() + 60 )
it'll actually increment by 60 days; you won't end up with a weird date like May 74th.
Keep in mind that months in javascript are zero-based, ie January is 0, February is 1, etc.
You can create a new date in javascript by new Date(yy, mm, dd)
or new Date('yy/mm/dd')
, so you could string-manipulate an input and create a date from that.
To compare two dates, you can subtract one from the other, and get the difference in milliseconds.
if ( dateA - dateB < 0 ) // dateB is greater than dateA (occurrs later)
and
var diff = Math.abs(dateA - dateB) // difference in ms, no matter which date is greater