Asked — Edited

Date Calculation

if I run this command:

$xhours = FmtTimeSpan(CDateTime("10/29/2016 1:00:00 PM") - CDateTime("10/31/2016 2:02:02 PM"), "hh")

I get 1. Which works great. And says that 2 pm is 1 hour from 1 pm.

But if I run this

$xhours = FmtTimeSpan(CDateTime("10/29/2016 3:00:00 PM") - CDateTime("10/31/2016 2:02:02 PM"), "hh")

I get 1. But not a negative 1 or even 0.

I am trying to figure out if the time is past or before the current time.

Any help would be appreciated


ARC Pro

Upgrade to ARC Pro

Unleash your creativity with the power of easy robot programming using Synthiam ARC Pro

#1  

Experimenting, if your time span exceeds 24 hours, it will not display the hours.

Can you explain more on what you are trying to do specifically? Are you wanting to take an action is a time/date has past?

PRO
USA
#2  

if the time/date is in the past I would like to take an action, execute a script or execute another if the date/time is in the future.

I know how to write the script based on the outcome of the time/date. Just cant figure a way to figure out if past or future time/date.

PRO
USA
#3  

@Dbeard,

For a moment i thought it was the same question you asked on this thread:

https://synthiam.com/Community/Questions/9760

there, you have all the elements to help you, sometimes is not so obvious ...

solution:



$eventDate = "10/29/2016 1:00:00 PM" 
$diff=CDateTime($eventDate)-CDateTime($date)

#diff will start with a "-" if the difference is negative
if (GetCharAt($diff,0) = "-")
  print("past")
else
  print("future")
endif

Let me know if it solves your problem.

PRO
USA
#4  

PTP:

Yes, it worked wonderfully. And cut down some of the code I had put together.

And I also learned the GetCharAt code also. A bonus.

Thanks very much.