Some examples to help make things clear...
if [LOCAL1] contains 5 then...
[LOCAL1] + 8 >> Returns a number type that equals 13
[LOCAL1] + “ is a number.” >> Returns a syntax error because the formula actually passed to the evaluator will look like: 5 + “ is a number.”
“[LOCAL1]” + “ is a number.” >> Returns a string that looks like: 5 is a number.
“[LOCAL1] is a number.” >> Also works and is the equivalent of the formula just above.
Using this background, if the [LOCAL3] var contains a saved datetime value in the form of 12/15/2010 10:49:00 it will fail in this formula: ph_minutesafter([LOCAL3],today())
But...it will suceed if the saved datetime value in [LOCAL3] looks like: 2010-12-15 10:49:00, or the formula was changed to ph_minutesafter(ph_getvar_dt(1,3),today())
To create a negative time value (before an event) use this form . . . “ph_relativetime ( 00:00:00,[SUNRISE]-15*60)“ which would be 15 minutes before SUNRISE.
You can specify a literal date, time, or datetime by using the format of "yyyy-mm-dd hh:mm:ss.ttt" That is with
dashes, not slashes between date items and no comma between the date and time.
[NOTE: the date is year-month-day ordered.]
For example the formula...
ph_relativedatetime(2013-12-01 13:38:15.306,90)
Will give you back a datetime that is 90 minutes later than the entered datetime... almost. The milliseconds portion will always be 0, as the ph_relativedatetime function truncates time to seconds. If you want millisecond precision, you must use the ph_relativedtprecise function.
If you are wondering why the function today() returns its output in mm/dd/yyyy hh:mm:ss format rather than the literal datetime input, it is due to Windows formatting of datetime values which are controlled by regional settings. So input is always yyyy-mm-dd hh:mm:ss.fff and output can vary (usually mm/dd/yyyy hh:mm:ss in the United States) based upon Windows regional settings.
To better understand how to create formulas with Date/Time & System values the following chart demonstrates how various functions resolve their output values...
Formula | Result |
ph_secondsafter(06:30:00, 06:32:00) | 120 |
[SUNRISE] | 22869 |
ph_relativetime(00:00:00,[SUNRISE]) | 06:25:26 |
ph_relativetime(00:00:00,[SUNRISE]-60) | 06:24:26 |
ph_relativetime(00:01:00,[SUNRISE]) | 06:26:26 |
ph_relativetime(02:00:00,90) | 02:01:30 |
Now() | 14:57:22:463 |
ph_relativetime(now(),30) | 14:57:52 |
Today() | 12/01/2013 14:57:22 |
ph_relativedatetime(today(),30) | 12/01/2013 14:57:52 |
ph_relativedatetime(datetime("09/23/13 12:00:00"),30) | 09/23/2013 12:30:00 |
ph_relativedatetime(2013-09-23 12:00:00,30) | 09/23/2013 12:30:00 |
datetime("09-23-13 08:15:00") | 09/23/2013 08:15:00 |
time("06:30:00") | 06:30:00 |
Now()>07:00:00 | True if after 7AM |
datetime(today(),08:00:00) | 12/01/2013 08:00:00 |