Variable to get last week number - VisualCron - Forum

Community forum

Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
Offline tomas.cerny  
#1 Posted : Friday, February 14, 2020 12:30:22 PM(UTC)
tomas.cerny

Rank: Paid support

Joined: 6/15/2017(UTC)
Posts: 4
Czech Republic
Location: Praha, Hlavni mesto, Karlin

Thanks: 1 times
Hello,

we run many jobs weekly and need to name output files in naming convention like Name_<year>_<cw>.csv, where cv is calendar week and year is a year of that week. Mostly we run scripts for previous (complete week). I would suggest to create new built in variable last week, that would return complete previous week. The best would be to have an option, how to format output (week number of last week - with leading zero, year of last week, start day (first day of last week), end day (last day of last week), first working day of last week, last working day of last week).

Example: On 14.2.2020 I use this function with output formatting year_cw and I'll get 2020_06.
Example 2: On 2. 1. 2020 I use this function with output formatting year_cw and I'll get 2019_52.

With current variables this could not be done effectively (scripting required, as seen here: https://www.visualcron.c...spx?g=posts&t=2199). The only option is to get current week number, but this makes troubles when years change.

Thank you.
Offline Gary_W  
#2 Posted : Friday, February 14, 2020 4:08:06 PM(UTC)
Gary_W

Rank: Paid support

Joined: 12/19/2016(UTC)
Posts: 222
United States
Location: Michigan, Dearborn

Thanks: 51 times
Was thanked: 78 time(s) in 68 post(s)
Dobry den! This 2-line powershell script can return the info you want. Note that the %V format character for week of the year is supposed to return a leading zero, but VC seems to suppress it.

#$save_date = (get-date "1/2/2020" ).AddDays(-7) # For testing
$save_date = (get-date).AddDays(-7)
get-date $save_date -uformat "%Y_%V"

Edited by user Friday, February 14, 2020 4:09:19 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Gary_W for this useful post.
Support on 2/14/2020(UTC)
Offline tomas.cerny  
#3 Posted : Monday, February 17, 2020 7:32:12 AM(UTC)
tomas.cerny

Rank: Paid support

Joined: 6/15/2017(UTC)
Posts: 4
Czech Republic
Location: Praha, Hlavni mesto, Karlin

Thanks: 1 times
Hi Gary_W,

thanks for posting this tip, I appreciate your help. I'm aware that many missing functions can be bypassed by Powershell and other means, however I thought it would be more convenient to have built-in function rather than coding it (I could write whole job into PowerShell script and wouldn't need VC at all :-). We try to keep our jobs as simple as possible, with your approach there is one more step needed.
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Scroll to Top