Link to home
Start Free TrialLog in
Avatar of mooriginal
mooriginalFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PowerShell datetime ADDdays function

Can anyone help please ...

I have the following code which is used to archive off weekly a file based on the template datestamp of the file in question - which is always the same.

The script works for later part of month and its dates but does not work for the earlier part of the month

it ran recently and threw following exception because its expects the front part of the date to be "5112012"
When in fact the date is with an extra 0 - 05112012


Copy-Item : Cannot find path 'C:\Powershell\WebReport\DiskSpaceReport_5112012.html' because it does not exist.

Can someone re-write this to work and not mind the 0?
powershell-example.txt
Avatar of t_busch
t_busch

You have to use

$filename = "DiskSpaceReport_" + $pastdate.Day.tostring().padleft(2,"0") + $pastdate.Month + $pastdate.Year+".html"

Open in new window


Best Regards

Thomas
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mooriginal

ASKER

I agree the convert to string is better use of the string ... now that i realise that ..