Computing.Net > Forums > Programming > Passing prior date into a variable

Passing prior date into a variable

Reply to Message Icon

Original Message
Name: djones
Date: July 17, 2007 at 06:24:25 Pacific
Subject: Passing prior date into a variable
OS: winxp
CPU/Ram: 1gig
Model/Manufacturer: mpc
Comment:

Ok so i need to get the prior days date into a variable in order to automate a few zip files. So far i have the date being echoed into a text file i.e. in today's text file i have Tue 07/17/2007 i want that date passed into a variable so that when called itll display 071707 (yyddmm) how would i go about accomplishing this?

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


Report Offensive Message For Removal

Response Number 1
Name: tonysathre
Date: July 17, 2007 at 09:05:49 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

@echo off
for /f "tokens=2" %%d in ('echo %date%') do (
for /f "tokens=1-3 delims=/" %%j in ('echo %%d') do (
set day=%%j
set month=%%k
set year=%%l
)
)
set year=%year:~2,3%
set mydate=%day%%month%%year%
echo %mydate%
pause
"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 2
Name: djones
Date: July 17, 2007 at 09:45:32 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

hey tony that worked like a charm but how would i modify that to get the previous date ie on the 17th i need mydate to reflect 071607?

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


Report Offensive Follow Up For Removal

Response Number 3
Name: djones
Date: July 17, 2007 at 10:44:19 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

i get i should put the code i have so far and explain a little better what i am trying to accomplish. everyday i have to unzip files that are date with yesterday's date and on mondays i have to unzip files that are dated with the previous fri,sat and sun dates. i wanna to automate all this but i am a little stumped. here is what i have so far


@echo off
for /f "tokens=2" %%d in ('echo %date%') do (
for /f "tokens=1-3 delims=/" %%j in ('echo %%d') do (
set day=%%j
set month=%%k
set year=%%l
)
)
set year=%year:~2,3%
set mydate=%year%%month%%day%
echo %mydate%
pause

::"C:\Program Files\WinZip\WZUNZIP.exe" \\dsave\y$\eFundsFTPMirror\D%mydate%.FISA.ISOUSR.ZIP "\\ncat3284a\d$\cat\Data\SwitchImportFiles\"
::"C:\Program Files\WinZip\WZUNZIP.exe" \\dsave\y$\eFundsFTPMirror\D%mydate%.FISA.DAILY.ZIP "M:\Accounting\eFunds\"
::"C:\Program Files\WinZip\WZUNZIP.exe" \\dsave\y$\eFundsFTPMirror\D%mydate%.RGNL.DNANA.ZIP "M:\Accounting\eFunds\"
::"C:\Program Files\WinZip\WZUNZIP.exe" \\dsave\y$\eFundsFTPMirror\D%mydate%.GTWY.DAILY.ZIP "M:\Accounting\eFunds\"
::"C:\Program Files\WinZip\WZUNZIP.exe" \\dsave\y$\eFundsFTPMirror\D%mydate%.GTWY.VVIPS.ZIP "M:\Accounting\eFunds\"
::copy \\dsave\y$\eFundsFTPMirror\D%mydate%.RGNL.DCU24.FX06599 m:\accounting\efunds\

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


Report Offensive Follow Up For Removal

Response Number 4
Name: djones
Date: July 17, 2007 at 10:47:29 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

the problem with what tony gave me is that thatll only get todays date and unfortunately i need yesterday's date. i want to have it so that on the 1st itll know to use the 31st for the date. also monday is the only day where i am unzipping 3 prior days worth of files.

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


Report Offensive Follow Up For Removal

Response Number 5
Name: tonysathre
Date: July 17, 2007 at 11:32:54 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

I think this one might be out of my league, now. M2 will probably be around later to finish this for you. But, to get the previous day into vars:

::==
@echo off
for /f "tokens=2" %%d in ('echo %date%') do (
for /f "tokens=1-3 delims=/" %%j in ('echo %%d') do (
set day=%%j
set month=%%k
set year=%%l
)
)
set /a day=%day%-1
if %day% lss 10 (
set day=0%day%
)
set year=%year:~2,3%
set mydate=%year%%month%%day%
echo %mydate%
::==

I didn't test this code, so If you get an error post it and I will debug it for you.


"Computer security." — Oxymoron


Report Offensive Follow Up For Removal


Response Number 6
Name: djones
Date: July 17, 2007 at 11:38:25 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

i didnt get an error. Today's date was displayed.

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


Report Offensive Follow Up For Removal

Response Number 7
Name: tonysathre
Date: July 17, 2007 at 11:47:24 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

Oops, sorry, I didn't notice you wanted it mmddyy.

Here is the code for mmddyy:

::==
@echo off
for /f "tokens=2" %%d in ('echo %date%') do (
for /f "tokens=1-3 delims=/" %%j in ('echo %%d') do (
set day=%%j
set month=%%k
set year=%%l
)
)
set /a day=%day%-1
if %day% lss 10 (
set day=0%day%
)
set year=%year:~2,3%
set mydate=%month%%day%%year%
echo %mydate%
::==

Again, this is untested.

"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 8
Name: djones
Date: July 17, 2007 at 11:50:13 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

this is wat is displayed when i run that new code 170607

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


Report Offensive Follow Up For Removal

Response Number 9
Name: tonysathre
Date: July 17, 2007 at 11:52:45 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

Try this:

::==
@echo off
for /f "tokens=2" %%d in ('echo %date%') do (
for /f "tokens=1-3 delims=/" %%j in ('echo %%d') do (
set month=%%j
set day=%%k
set year=%%l
)
)
set /a day=%day%-1
if %day% lss 10 (
set day=0%day%
)
set year=%year:~2,3%
set mydate=%month%%day%%year%
echo %mydate%
pause
::==


"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 10
Name: djones
Date: July 17, 2007 at 12:00:04 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

worked like a charm

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


Report Offensive Follow Up For Removal

Response Number 11
Name: FishMonger
Date: July 17, 2007 at 12:30:09 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

Tony,

How do you handle the 1st of the month?

Given this date: 08/01/07
your script will produce: 080007


Report Offensive Follow Up For Removal

Response Number 12
Name: djones
Date: July 17, 2007 at 12:32:34 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

Fish i was wondering the same thing

Dominic Adair-Jones
IT Specialist
FDIC Federal Credit Union
www.fdicfcu.org


Report Offensive Follow Up For Removal

Response Number 13
Name: FishMonger
Date: July 17, 2007 at 13:17:31 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

Reformatting the date string in a batch file is easy, but doing date calculations is not. You'd be better off using a more appropriate scripting language. I can show you how to do this in Perl or others can show you VBscript or Python.


Report Offensive Follow Up For Removal

Response Number 14
Name: tonysathre
Date: July 17, 2007 at 14:57:00 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

Good point guys, thanks. I didn't even think about that.

Untested, but should work:

::==
::@echo off
for /f "tokens=2" %%d in ('echo %date%') do (
for /f "tokens=1-3 delims=/" %%j in ('echo %%d') do (
set month=%%j
set day=%%k
set year=%%l
)
)
set /a day=%day%-1
if %day% lss 10 (
set day=0%day%
)
if %day%==00 (
set day=01
)
set year=%year:~2,3%
set mydate=%month%%day%%year%
echo %mydate%
pause
::==

"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 15
Name: tonysathre
Date: July 17, 2007 at 15:02:39 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

Nevermind, that won't work. I think they are correct in saying another language would probably best suit your needs. Unless of course, M2 can come up with something.

"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 16
Name: Razor2.3
Date: July 17, 2007 at 20:15:00 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

Yeah, getting the past 7 days in VBScript is really, really easy.

MsgBox Date - 7


Report Offensive Follow Up For Removal

Response Number 17
Name: Mechanix2Go
Date: July 18, 2007 at 03:25:24 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

The 'date math' thing comes up at least once a month. Never a happy subject. The only way out is to convert to a 'julian-like' date, do the math, then convert back. Messy.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 18
Name: tonysathre
Date: July 18, 2007 at 10:53:51 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

Or, with that date calculator utility I posted a while back. I never did try it out though.


"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 19
Name: Mechanix2Go
Date: July 18, 2007 at 11:31:41 Pacific
Subject: Passing prior date into a variable
Reply: (edit)

tony,

It works great.



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Passing prior date into a variable

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software