thordk
asked on
Batch: need to generate timestamp for 'today' AND for 'yesterday'
Hello,
I need to generate 2 strings that i will pass on to a program - the first is the current date:
DDMMYY
Which is easy enough.
The other one is 'yesterday' - current day minus 1 - also in the same format:
DDMMYY
Is that possible at all in a batch-script ?
hope you can help, thanks.
I need to generate 2 strings that i will pass on to a program - the first is the current date:
DDMMYY
Which is easy enough.
The other one is 'yesterday' - current day minus 1 - also in the same format:
DDMMYY
Is that possible at all in a batch-script ?
hope you can help, thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you are happy with your current method to get ddmmyy from a real date just get the raw date with:
@echo off
echo wscript.echo date() -1 >> "%temp%\yesterday.vbs"
for /f "tokens=1" %%a in ('cscript "%temp%\yesterday.vbs"') do set yesterday=%%a
Steve
@echo off
echo wscript.echo date() -1 >> "%temp%\yesterday.vbs"
for /f "tokens=1" %%a in ('cscript "%temp%\yesterday.vbs"') do set yesterday=%%a
Steve
ASKER
Thanks alot
This article may help as well ;-)...
https://www.experts-exchange.com/questions/21316459/Get-Yesterday-date-in-MS-DOS-Batch-file.html
Best regards
karwak
https://www.experts-exchange.com/questions/21316459/Get-Yesterday-date-in-MS-DOS-Batch-file.html
Best regards
karwak
ASKER
Thanks alot steve :)
No problem, glad it helped. Steve
ASKER
Sidequestion:
Could i easily change that code to generate the "previous timestamp" to:
-1 week
and also
-1 month ?
for 3 seperate batchjobs ?
Could i easily change that code to generate the "previous timestamp" to:
-1 week
and also
-1 month ?
for 3 seperate batchjobs ?
of course. It gets less messy if the VBS already exists but you just need to use date() -7 for 1 week for instance and DateAdd("M",-1,date()) to take off a month. Lots of other options on DateAdd if you give it a google etc. If stuck on getting this working post and will look later
Steve
Steve
Set objshe = WScript.CreateObject("WScr ipt.Shell" )
a = now-1
dat01 = year(a) & "-" & month(a) & "-" & day(a)
msgbox(dat01)
'=== to run a program 0 = hidden
a = "notepad.exe"
objshe.Run a,8, false
a = now-1
dat01 = year(a) & "-" & month(a) & "-" & day(a)
msgbox(dat01)
'=== to run a program 0 = hidden
a = "notepad.exe"
objshe.Run a,8, false
ASKER
Steve - thanks alot that works like a charm :)
No problem!
Steve
Steve
year(date() -1) to right(year(date() -1),2)
and
year(date()) to right (year(date(),2)
Steve