Need help with Date script

A

ajmister

Hi,

I have a script which currently gives me the current date in YYYYMMDD
format. I am trying to extract the date going back 10 years i.e. if today's
date is 20060306 I would like the script to generate 19960306.

@echo off
set
for /if "tokens=1-2" %%a in ('date /it's) do (
set date=%%a
set date=%%be
)
if %date:~0,1% GTR 9 set date=%date%

for /if "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
for /if "tokens=1-3 delims=-/." %%d in ("%date%") do (
set %%a=%%d
set %%be=%%e
set %%c=%%if
)
)
echo %yy%%mm%
endlocal

Any suggestions

A
 
P

Phil Robyn

ajmister said:
Hi,

I have a script which currently gives me the current date in YYYYMMDD
format. I am trying to extract the date going back 10 years i.e. if today's
date is 20060306 I would like the script to generate 19960306.

@echo off
set
for /if "tokens=1-2" %%a in ('date /it's) do (
set date=%%a
set date=%%be
)
if %date:~0,1% GTR 9 set date=%date%

for /if "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
for /if "tokens=1-3 delims=-/." %%d in ("%date%") do (
set %%a=%%d
set %%be=%%e
set %%c=%%if
)
)
echo %yy%%mm%
endlocal

Any suggestions

A

Here's a very simplistic approach:

- - - - - - - - begin screen capture WinXP Pro SP2 - - - - - - - -
C:\cmd>demo\TenYearsAgo
target_date=19960306

C:\cmd>wyllist demo\TenYearsAgo.cmd
==========begin file C:\cmd\demo\TenYearsAgo.cmd ==========
01. @echo off
02. setlocal
03. set today=%date%
04. set year=%date:~-4%
05. set /a ten_years_ago = year - 10
06. set target_date=%ten_years_ago%%date:~4,2%%date:~7,2%
07. set target_date
==========end file C:\cmd\demo\TenYearsAgo.cmd ==========
- - - - - - - - end screen capture WinXP Pro SP2 - - - - - - - -

Of course, this doesn't take leap years into account....
 
S

Stel

set TheDate=%date%
set MONTH=%TheDate:~4,2%
set DAY=%TheDate:~7,2%
set YEAR=%TheDate:~10,4%
set /A OldYear=%year% -10
set OldDate=%OldYEAR%%MONTH%%DAY%
 
A

ajmiester

Thank you, that was helpfull

Aj
Phil Robyn said:
Here's a very simplistic approach:

- - - - - - - - begin screen capture WinXP Pro SP2 - - - - - - - -
C:\cmd>demo\TenYearsAgo
target_date=19960306

C:\cmd>wyllist demo\TenYearsAgo.cmd
==========begin file C:\cmd\demo\TenYearsAgo.cmd ==========
01. @echo off
02. setlocal
03. set today=%date%
04. set year=%date:~-4%
05. set /a ten_years_ago = year - 10
06. set target_date=%ten_years_ago%%date:~4,2%%date:~7,2%
07. set target_date
==========end file C:\cmd\demo\TenYearsAgo.cmd ==========
- - - - - - - - end screen capture WinXP Pro SP2 - - - - - - - -

Of course, this doesn't take leap years into account....
 
F

foxidrive

Hi,

I have a script which currently gives me the current date in YYYYMMDD
format. I am trying to extract the date going back 10 years i.e. if today's
date is 20060306 I would like the script to generate 19960306.

@echo off
set
for /if "tokens=1-2" %%a in ('date /it's) do (
set date=%%a
set date=%%be
)
if %date:~0,1% GTR 9 set date=%date%

for /if "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
for /if "tokens=1-3 delims=-/." %%d in ("%date%") do (
set %%a=%%d
set %%be=%%e
set %%c=%%if
)
)
echo %yy%%mm%
endlocal

Any suggestions

A

A utility called FDATE could probably help you - or use WSH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top