1.

Solve : Expire Batch - Date comparison?

Answer»

I want to have a hard coded date in a BATCH file that checks system date to verify if batch should be run.

If system Date is past EXPIRED Date then fail. Is this possible? Do I need to convert date to something else?

Code: [Select]Echo OFF

set M=%DATE:~4,2%
set D=%DATE:~7,2%
set Y=%DATE:~10,4%

set ExpiredDATE=06/18/2009

if %ExpiredDATE% GTR %M%/%D%/%Y% ECHo Date:"%M%/%D%/%Y%" ^& ExpiredDATE:"%ExpiredDATE%" Expired & pause & EXIT

Echo Date:"%M%/%D%/%Y%" ^& ExpiredDATE:"%ExpiredDATE%" If Date gtr expireddate failed?
Pause
THANKS for the help.


EDIT:I think I totally brainfarted and figured this out. I will post if I need help. Blah its been a long day. Ok ... sorry for the second post. I changed the code to this but it still expires. What am I doing wrong with DATE?

Code: [Select]Echo OFF

set M=%DATE:~4,2%
set D=%DATE:~7,2%
set Y=%DATE:~10,4%

set ExpiredDATE=06/14/2010

if %M%/%D%/%Y% GTR %ExpiredDATE% ECHo Date:"%M%/%D%/%Y%" ^& ExpiredDATE:"%ExpiredDATE%" Expired & pause & EXIT

Echo Date:"%M%/%D%/%Y%" ^& ExpiredDATE:"%ExpiredDATE%" If Date gtr expireddate failed?
PauseCompare dates using YYYYMMDD format.

Cool. That appears to work.

Do you know why that works and MMDDYYYY doesn't? Thanks for the help. You may have your Date Format set to: YYYYMMDD

Depending upon where you LIVE, the Date format is different. Quote from: nothlit on JUNE 16, 2009, 07:21:49 AM

Do you know why that works and MMDDYYYY doesn't? Thanks for the help.

The IF command does not compare dates, it simply looks at two values and returns True or False.

IF 06/16/2009 GTR 06/14/2010 will always return True (06162009 is GTR 06142010)

IF 2009/06/16 GTR 2010/06/14 will always return False while the system date value is less than the hard coded date value (20090616 is LSS 20100614)

(Edit in italics.)

You're welcome.

D.


Discussion

No Comment Found