-
9 Oct 2012 8:51 AM #1
Answered: Compare TimeField Value with Time From Date
Answered: Compare TimeField Value with Time From Date
Good day all!!!
I'm have a timefield "TimeField01". I'm trying to get the time from the timefield and compare it with the time from new Date().
I see in the documentation clearTime which removes the time from the date, but there is no clearDate. I would like to remove the date from the timefield and from new Date() and then compare the two times. How would I go about doing this???
-
Best Answer Posted by vietits
You can set the two dates to the same date, then using getTime() to convert them to miliseconds to compare.
Code:function compareTime(time1, time2){ time1.setFullYear(1970, 0, 1); time2.setFullYear(1970, 0, 1); return time1.getTime() - time2.getTime(); }
-
9 Oct 2012 6:18 PM #2
You can set the two dates to the same date, then using getTime() to convert them to miliseconds to compare.
Code:function compareTime(time1, time2){ time1.setFullYear(1970, 0, 1); time2.setFullYear(1970, 0, 1); return time1.getTime() - time2.getTime(); }
-
11 Oct 2012 8:45 AM #3


Reply With Quote