It is currently March 28th, 2024, 8:57 pm

difference between two Times

Get help with creating, editing & fixing problems with skins
scub
Posts: 30
Joined: May 16th, 2015, 10:37 pm

difference between two Times

Post by scub »

i have a string with this format: May 19 (string) 6:00 (string) PM EDT (string).
i'd like to compare the time to current time and find the difference. i don't care for the date, just the time.

so for example, if it's 6:01 now, i will get "1 minute ago"
since the time "6:00" is already a string, i suppose take the current time min and subtract it from the strings last two digits? i suppose this would be the easiest method? as i think no more than 60 mins will vary between the string time and the current time.

TY.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: difference between two Times

Post by ikarus1969 »

Maybe you want to use the following (i'm quite sure there's a more sphisticated solution, but until someone else will provide that... ;-) )

"Measure_DateString" is the measure that provides the string with the date
"Measure_CurrentTime" is the measure for the current time
"Measure_Difference_in_minutes" is the measure that result is the difference in minutes

I included the hour in the calculations for the case the difference will be more than 59 minutes sometimes.

Assumption: the time in the string is lower than the current time (otherwise the result will be negative)

Code: Select all

[Measure_DateString]
Measure=STRING
String=May 19 (string) 6:00 (string) PM EDT

[Measure_DateString_TIME]
Measure=STRING
String=[Measure_DateString]
RegexpSubstitute=1
Substitute="^.+(\d+):(\d+).+$":"\1\2"
DynamicVariables=1

[Measure_DateString_TIME_CALC]
Measure=CALC
Formula=[Measure_DateString_TIME]
DynamicVariables=1

[Measure_CurrentTime]
Measure=TIME
Format=%H%M

[Measure_CurrentTime_CALC]
Measure=CALC
Formula=Measure_CurrentTime

[Measure_Difference_in_minutes]
Measure=CALC
Formula=FLOOR((Measure_CurrentTime_CALC - Measure_DateString_TIME_CALC) / 100) * 60 + ((Measure_CurrentTime_CALC - Measure_DateString_TIME_CALC) % 60)
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: difference between two Times

Post by jsmorley »