Commands & Syntax >

www.MacroToolworks.com

Expressions & Time Calculations

 

Expressions can be used as command parameters including "if" command condition. Expressions have this syntax:
 

EXPR(expression) 

 

or

 

EXPRXX(expression) 

 

Note: XX specifies how many digits follow after decimal point (real numbers precision) if the expression calculates in real numbers.

 

Expressions can be used as a parameter for almost all commands. Expressions support all basic mathematical operations and brackets.

 Example1:  <mm>(EXPR(%_vScreenWidth%/2), EXPR(%_vScreenHeight%/2))
 Example2:  <varset>("vPercent=EXPR(100*(%vItems%/%vItemsTotal%))","")

The expressions support also date/time arithmetic's.  The date/time must be in ISO format which is "yyyy-mm-ddThh:mi:ss", for example 2018-04-16T21:05:58.  The difference between two times is "time span" that has this format "days hh:mi:ss", for example 4 02:0:01 (four days and two hours and one second difference).  The time span is also used to add/subtract amount of time to/from given time.  This operations are supported:

 "days hh:mi:ss" = "yyyy-mm-ddThh:mi:ss" - "yyyy-mm-ddThh:mi:ss"
 "yyyy-mm-ddThh:mi:ss" = "yyyy-mm-ddThh:mi:ss" +  "days hh:mi:ss"
 "yyyy-mm-ddThh:mi:ss" = "yyyy-mm-ddThh:mi:ss" -  "days hh:mi:ss"
 "days hh:mi:ss" = "days hh:mi:ss"+"days hh:mi:ss"
 "days hh:mi:ss" = "days hh:mi:ss"-"days hh:mi:ss"

 Example3:  <varset>("vTomorrowDate=EXPR(%_vCurrDateTime_ISO%+1 0:0:0)","") <#> 1 day later (next day)
 Example4:  <varset>("vDate=EXPR(%_vCurrDateTime_ISO%-10 13:45:10)","") <#> What date was before 10 days, 13 hours, 45 minutes and 10 seconds
 Example5:  <varset>("vTimeSpan=EXPR(%_vCurrDateTime_ISO%-2005.11.21 13:45:00)","") <#> How much time left since 2005/11/21, 13:45:00

 There are these limitations on time input: 1970 <= yyyy<= 3000; 1 <= mm <= 12; 1 <= dd <= 31; 0 <= hh <= 23; 0 <= mi <= 59; 0 <= ss <= 59