Last day of previous month

Discuss RoboTask here
Post Reply
tcarvalho
Posts: 25
Joined: Mon Feb 24, 2020 5:46 pm

Last day of previous month

Post by tcarvalho »

Is there a variable combination that can have Robotask populate the last date of a previous month? So for example when running a report in the end date for the date field I need to populate 06/30/2020 as that was the final day of the previous month.
kunkel321
Posts: 30
Joined: Sun Mar 15, 2020 5:23 pm

Re: Last day of previous month

Post by kunkel321 »

tcarvalho wrote:Is there a variable combination that can have Robotask populate the last date of a previous month? So for example when running a report in the end date for the date field I need to populate 06/30/2020 as that was the final day of the previous month.
I'm somewhat new to Robotask... But I'll bet you could get today's date as format "dd" then subtract "dd+1" from the current date. For example today is July 14th, so that would be "14." Add one is 15. So then use the Global Variable called {DateIncDays(-7)} which appears to be "current date +/- number of days. Today minus 15 should be June 30.

Maybe?

EDIT: Actually, As I look at a calendar... Maybe you wouldn't need to add +1. Today (14th) minus 14 would be one day before July 1st. Hence June 30th.
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Last day of previous month

Post by Oleg »

Maybe you wouldn't need to add +1. Today (14th) minus 14 would be one day before July 1st. Hence June 30th.
Yes, of course.
Use the expression {DateIncDays(-{Day})}

Also look at the small example

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|"Task222"
Hide=INTEGER|0
ID=INTEGER|1946255170
LogOnAsUser=INTEGER|1
Name=STRING|"last date of previous month"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER

[Actions\Action1]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""last date of previous month"""
Params=FOLDER

[Actions\Action1\Params]
icon=STRING|"1"
msg0=STRING|"last date of previous month"
msg1=STRING|"{DateIncDays(-{day})}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"

Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Oleg Yershov
kunkel321
Posts: 30
Joined: Sun Mar 15, 2020 5:23 pm

Re: Last day of previous month

Post by kunkel321 »

Wow -- only one step needed in the task. Pretty cool. 8-)
tcarvalho
Posts: 25
Joined: Mon Feb 24, 2020 5:46 pm

Re: Last day of previous month

Post by tcarvalho »

Oleg wrote: Use the expression {DateIncDays(-{Day})}
Thank you Oleg, but I forgot one of the reports is actually 2 months behind, but again needs to be the last day of that month. Is that also possible with this expression?
kunkel321
Posts: 30
Joined: Sun Mar 15, 2020 5:23 pm

Re: Last day of previous month

Post by kunkel321 »

The only way I can imagine this working (for month before last), is to use a loop.

Start with a date that is "today minus 60 days." Then increment it forward one day at a time. With each loop save the currently evaluated date (formatted as "dd") to a variable, and the day after the currently evaluated day as another variable. When "Var_day_after" is less than "var_currently_evaluated" then break from the loop--you are at the end of the month.
Post Reply