1.

Solve : Expiry date...?

Answer»

Hi... NEWBIE here.

I writing a simple BATCH to call for an action on or after a specify date.

The day and month did work, but once the year is change, the batch doesn't work anymore.

any suggestion?

Btw... is in MS dos.

Quote

@echo off
PATH=C:\


IF "%date%" LEQ "11/12/2005" (
GOTO 1
) ELSE (
GOTO 2
)

:1
Echo Expired...
pause
goto END

:2
Echo Not Expired Yet!
pause
goto END

Pause

:END
Quote
Hi... Newbie here.

I writing a simple batch to call for an action on or after a specify date.

The day and month did work, but once the year is change, the batch doesn't work anymore.

any suggestion?

Btw... is in MS dos.



sorry... i tested, only the DAY can work...
Your code certainly doesn't look like it's running on a MS-DOS machine. In any case when dealing with date comparisons, it is advisable to have them formatted YYYYMMDD.

Code: [Select]
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set today=%%c%%a%%b
if "%today%" leq "20051211" (
GOTO 1
) ELSE (
GOTO 2
)


I couldn't tell if your date format is MM/DD/YYYY or DD/MM/YYYY. If I goofed it, reverse the %%a and %%b variables at the end of the first line.

Hope this helps. Quote
Your code certainly doesn't look like it's running on a MS-DOS machine. In any case when dealing with date comparisons, it is advisable to have them formatted YYYYMMDD.

Code: [Select]for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set today=%%c%%a%%b
if "%today%" leq "20051211" (
GOTO 1
) ELSE (
GOTO 2
)

I couldn't tell if your date format is MM/DD/YYYY or DD/MM/YYYY. If I goofed it, reverse the %%a and %%b variables at the end of the first line.

Hope this helps.



ya Sidewinder, i already got the solution and it is actually the same as what u have quoted.

But i still dun understand how the below function work...
"for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set today=%%c%%a%%b"

Thank a lot pal...


Discussion

No Comment Found