aviator21114
asked on
Convert text variables containing mm-dd-yyyy to a date format so I can compare
Uncle, I cry uncle.... I've browsed a bunch of code and can't seem to hone in on what I need.
I have two date variables let's call them date1 date2. they are strings always in the format of mm-dd-yyyy. All I want to do is determine the number of days between these two dates. I'm pretty sure I first need to convert these to another format but I'm not sure how to code this... can someone show me the javascript code to do this?
Thanks,
I have two date variables let's call them date1 date2. they are strings always in the format of mm-dd-yyyy. All I want to do is determine the number of days between these two dates. I'm pretty sure I first need to convert these to another format but I'm not sure how to code this... can someone show me the javascript code to do this?
Thanks,
Use gettime() on your dates:
(date1.getTime() - date2.getTime() )/ (24*60*60*1000)
will give you the number of days between the dates
HTH,
Dan
(date1.getTime() - date2.getTime() )/ (24*60*60*1000)
will give you the number of days between the dates
HTH,
Dan
ASKER
GaryC123.... what's happening on lines 10 and 11 with the subscripts? Date1(0) -1 can you define this construct?
Your months are in range 1-12 and JS needs them in the range 0-11.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window