Link to home
Start Free TrialLog in
Avatar of thordk
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.



ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland 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
Sorry I see you wanted YY not YYYY.  Just need to change

year(date() -1)  to   right(year(date() -1),2)
and
year(date()) to right (year(date(),2)

Steve
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
Avatar of thordk
thordk

ASKER

Thanks alot
Avatar of thordk

ASKER

Thanks alot steve :)

No problem, glad it helped. Steve
Avatar of thordk

ASKER

Sidequestion:

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
Set objshe = WScript.CreateObject("WScript.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
Avatar of thordk

ASKER

Steve - thanks alot that works like a charm :)
No problem!
Steve