Date Roll Over

Discuss RoboTask here
Post Reply
AsuranDex
Posts: 2
Joined: Thu Dec 12, 2019 2:49 pm

Date Roll Over

Post by AsuranDex »

I'm using a task that opens my reporting software and runs a report from a date 2 days in the future to that date +1 calendar month: eg- 10/11/2019 - 10/12/2019. Now this isn't a problem, as for the start date i just user {DateIncDays(+2)} and in the end date i user {IncDays(+2)}/{IncMonths(+1)}/{Year}. The issue arises when the date in a months time, is next year.

Is there a variable that i can do which is essentially: "Today Date + 2 days + 1 Month" with the output of "dd/mm/yyyy", so that it will automatically roll over the year, like {DateIncDays(+)} does if the + days on that leads into the next month? Having {IncYear(+1)} works for most of December, but when the start date rolls over to next year, the report dates become for eg: 02/01/2020 - 02/01/2020, because while the day number rolls over, the month and year number just takes that days month + year (12/2019) and adds 1 to both.

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

Re: Date Roll Over

Post by Oleg »

Look at the example below.
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
The you can see the task in the task editor and test it

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1604865554
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task250"
Hide=INTEGER|0
ID=INTEGER|95064015
LogOnAsUser=INTEGER|1
Name=STRING|"add Days and months  ""DateIncMonths"" custom function"
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
Action5=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""TM"" with value ""{Date}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"1"
varname=STRING|"TM"
varvalue=STRING|"{Date}"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""D_DAYS"" with value ""2"""
Params=FOLDER

[Actions\Action2\Params]
=STRING|""
expand=STRING|"0"
varname=STRING|"D_DAYS"
varvalue=STRING|"2"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""D_MONTHS"" with value ""1"""
Params=FOLDER

[Actions\Action3\Params]
expand=STRING|"0"
varname=STRING|"D_MONTHS"
varvalue=STRING|"1"

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

[Actions\Action4\Params]
expression=STRING|"DateIncMonth(""{tm}"", {d_days}, {d_months})"
line00000000=STRING|"function DateIncMonth(tm, add_days, add_months)"
line00000001=STRING|"  DateIncMonth = DateAdd(""d"", CInt(add_days), CDate(tm))"
line00000002=STRING|"  DateIncMonth = DateAdd(""m"", CInt(add_months), DateIncMonth)"
line00000003=STRING|"end function"
line00000005=STRING|"'logmessage(DateIncMonth(""12.12.2019"", 2, 1))"
linecount=STRING|"6"
loadfromfile=STRING|"1"
variable=STRING|"newTime"

[Actions\Action5]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""DateIncMonth result:"""
Params=FOLDER

[Actions\Action5\Params]
icon=STRING|"1"
msg0=STRING|"DateIncMonth result:"
msg2=STRING|"Current date: {tm}"
msg3=STRING|"Add days: {d_days}"
msg4=STRING|"Add months: {d_months}"
msg6=STRING|"New Date: {NewTime}"
msg7=STRING|"formatted result: {DateTimeToFormat({NewTime},dd/mm/yyyy)}"
msgcount=STRING|"8"
playsound=STRING|"0"
showmessage=STRING|"1"
Oleg Yershov
AsuranDex
Posts: 2
Joined: Thu Dec 12, 2019 2:49 pm

Re: Date Roll Over

Post by AsuranDex »

Thank you very much, that greatly appreciated! Made life so much easier!
Post Reply