In Client Script, how can I compare 2 dates(with time) that are in different format.

JLeong
Mega Sage

In Client Script, how can I compare 2 dates(with time) that are in different format.

ex   yyyy-mm-dd HH:mm:ss and MM-dd-yyyy hh:mm:ss (12 hours)

Somehow I need to convert the 2nd date&time to system format and then compare to the first date. But I do not know how. Please assist.

1 ACCEPTED SOLUTION

Using "getDisplayValue()" will retrieve the date/time in the person's timezone and display format.   So you could use that on both date variables to force them into the same timezone.



gdate.getDisplayValue()


View solution in original post

13 REPLIES 13

Using "getDisplayValue()" will retrieve the date/time in the person's timezone and display format.   So you could use that on both date variables to force them into the same timezone.



gdate.getDisplayValue()


I use very similar code here with no problems.   We are multi timezone too


this is one of the validation scripts checking the dates / times of the planned change



g_form.hideFieldMsg('end_date');


var dtStartForm = g_form.getValue('start_date');


var dtStart = getDateFromFormat(dtStartForm,g_user_date_time_format);


if (dtStartForm != '') {


      var dtEndForm = g_form.getValue('end_date');


      var dtEnd = getDateFromFormat(dtEndForm, g_user_date_time_format);


      //g_form.addInfoMessage('Start Date : ' + dtStart + ' : End Date : ' + dtEnd);


      if (dtEnd < dtStart) {


              g_form.showFieldMsg('end_date', 'Planned end date cannot be before start date', 'error');


      }


}



Thank you guys sooo much! This solved the issue!!!


As Jim Coyne (CompuCom) suggested, timezone is no big issue.


-Anurag