Date format as a {Variable}

Discuss RoboTask here
Post Reply
george
Posts: 25
Joined: Sun Mar 25, 2018 3:02 pm

Date format as a {Variable}

Post by george »

Hi, I was wondering if there is a way I can insert a variable in date format (for example 2019-13-09), and add or substract days taking that value to use them later.
I know you can do it with the current date: {DateTimeToFormat({DateIncDays(+2)},yyyy/mm/dd)} (adding two days to the current date)

But can it be done with an input variable using any future or past date? :geek:

Thanks
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Date format as a {Variable}

Post by Oleg »

If your variable contains some date (in you regional format) you can use VB Evaluate action to calculate new date
Look at mu example:

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task630"
Hide=INTEGER|0
ID=INTEGER|-1000589786
LogOnAsUser=INTEGER|1
Name=STRING|"Add and Subtract days"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""MYVAR"" with value ""{FormatToDateTime(2014-02-19,yyyy-mm-dd)}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"1"
varname=STRING|"MYVAR"
varvalue=STRING|"{FormatToDateTime(2014-02-19,yyyy-mm-dd)}"

[Actions\Action2]
ActionID=STRING|"A_SCRIPT_VBEVALUATE"
Enabled=INTEGER|-1
Name=STRING|"VB Evaluate"
Params=FOLDER

[Actions\Action2\Params]
expression=STRING|"DateAdd(""d"", 2, Cdate(""{MyVar}""))"
linecount=STRING|"0"
loadfromfile=STRING|"1"
variable=STRING|"MyVarAdd2"

[Actions\Action3]
ActionID=STRING|"A_SCRIPT_VBEVALUATE"
Enabled=INTEGER|-1
Name=STRING|"VB Evaluate"
Params=FOLDER

[Actions\Action3\Params]
expression=STRING|"DateAdd(""d"", -2, Cdate(""{MyVar}""))"
linecount=STRING|"0"
loadfromfile=STRING|"1"
variable=STRING|"MyVarMinus2"

[Actions\Action4]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action4\Params]
message=STRING|"{myvar}; {MyVarAdd2}; {MyVarMinus2}"
type=STRING|"3"
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.

Read more about DateAdd function here
Oleg Yershov
george
Posts: 25
Joined: Sun Mar 25, 2018 3:02 pm

Re: Date format as a {Variable}

Post by george »

Works great, thanks Oleg! 8-)
Post Reply