The CreatorCon Call for Content is officially open! Get started here.

comparison between different times

Shir Sharvit
Tera Contributor

Hey
How do I reverse the string - '18:00:00'
for the time 18:00:00
for comparison between different times.

 

Thanks. Shir

12 REPLIES 12

Community Alums
Not applicable

Hi @Shir Sharvit ,

Please try below script 

 

var hms = "18:00:00";
var target = new Date("1970-01-01T" + hms);
gs.log(target);

 

Or 

var now = new Date();
var nowDateTime = now.toISOString();
var nowDate = nowDateTime.split('T')[0];
var hms = '18:00:00';
var target = new Date(nowDate + 'T' + hms);
gs.log(target);

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

sorry it doesn't work for me

Anubhav24
Mega Sage

Hi @Shir Sharvit ,

Before doing the addition can you convert the dates using getNumericValue() functions it converts the date to milliseconds and then you can simply do the comparison and once you have the value of the date based on your logic you can set it back using setNumericValue().

 

Please mark helpful/correct if my response helped you.