Week to date
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 1
- Joined: Mon Apr 23, 2012 8:33 pm
Week to date
I am writing a script to pull a report from a program we use and i need to be able to put in the the date for monday of that week with the 2nd date being todays date. Is there an easy way to get the date. I will eventually also need to do Month to date as well.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
So, get the day of the week using DayOfWeek. This gives a number where 1 is Sunday. So to get Monday's date we want to subtract that number of days minus one from today's date:
Code: Select all
//get day of week where 1 is Sunday
DayOfWeek>dow
//get tday's date
GetDate>the_date
//So Monday is today - dow-1
Sub>the_date,{%dow%-1}
//now if we want we can split out the parts to make our own format
DatePart>the_date,D,day_part
DatePart>the_date,M,month_part
DatePart>the_date,Y,year_part
//now we can use these in our filename
Let>filename=myfile_%year_part%-%month_part%-%day_part%.txt
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Actually you want to subtract that number of days minus 2, not 1, and also add some code to get the correct date if it runs on a Sunday. Something like:mtettmar wrote:So, get the day of the week using DayOfWeek. This gives a number where 1 is Sunday. So to get Monday's date we want to subtract that number of days minus one from today's date:
Code: Select all
//get day of week where 1 is Sunday
DayOfWeek>dow
//make it work for Sundays
If>dow=1
Let>dow=8
EndIf
//get tday's date
GetDate>the_date
//So Monday is today - dow-2
Sub>the_date,{%dow%-2}
etc.