bfelton Posted February 8, 2019 Posted February 8, 2019 (edited) I am wondering if there are any resident batch file experts on here.. I am looking to run some reports in commandreporter and want to set the end date of the report to "one week from today". I would appreciate any help! SIMS_Dash_B.txt Edited February 8, 2019 by bfelton
Arthur Posted February 8, 2019 Posted February 8, 2019 If you add the following code to your batch file it will calculate what the date is one week from today (via PowerShell) and store it in the 'TodayPlusOneWeek' variable. FOR /F %%i IN ('powershell ^(Get-Date^).AddDays^(+7^).ToString^('dd-MM-yyyy'^)') DO ( SET TodayPlusOneWeek=%%i ) ECHO %TodayPlusOneWeek% 1
bfelton Posted February 8, 2019 Author Posted February 8, 2019 I will give it a go, thanks for the response!
bfelton Posted February 8, 2019 Author Posted February 8, 2019 If you add the following code to your batch file it will calculate what the date is one week from today (via PowerShell) and store it in the 'TodayPlusOneWeek' variable. FOR /F %%i IN ('powershell ^(Get-Date^).AddDays^(+7^).ToString^('dd-MM-yyyy'^)') DO ( SET TodayPlusOneWeek=%%i ) ECHO %TodayPlusOneWeek% Will this take into account different length months and leap years?
Arthur Posted February 8, 2019 Posted February 8, 2019 Will this take into account different length months and leap years? Good question! If you use PowerShell to add 7 days onto 22/02/2020, it will return 29/02/2020 and not 01/03/2020. $Date = Get-Date -Year 2020 -Month 02 -Day 22 $Date.AddDays(+7).ToString('dd-MM-yyyy') Do the same calculation with 22/02/2021 and you will get 01/03/2021. tl;dr. If Windows can handle different length months and leap years, PowerShell will too. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now