Need help with Date script

  • Thread starter Thread starter ajmister
  • Start date Start date
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
 
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....
 
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%
 
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....
 
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.
 
Back
Top