Computing.Net > Forums > Programming > Batch File 'Time Since'

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File 'Time Since'

Reply to Message Icon

Name: jcgun
Date: May 9, 2009 at 03:37:34 Pacific
OS: Windows Vista
Subcategory: Batch
Comment:

Hey!
i've finally got my batch working, and now i'm just smoothing things out.
is there a way to automatically calculate the the number of days since a certain date??



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: May 11, 2009 at 15:39:50 Pacific
Reply:

Hi
This Help

@echo off
cls
if (%6)==() goto Syntax
echo Date1=%1/%2/%3
call :CalcDateNo %1 %2 %3
set Date1=%Z%
echo Date1 No=%Z%
call :CalcDateNo: %4 %5 %6
echo Date2=%4/%5/%6
set /a Diff=%Z%-%Date1%
echo Date2 No=%Z%
echo Diff=%Diff%
exit /b


:CalcDateNo %1 %2 %3
set Day=%1
set Month=%2
set Year=%3

rem Delele Leading Zeros
set Char=%Day:~0,1%
if %Char%==0 set Day=%Day:~1,1%
set Char=%Month:~0,1%
if %Char%==0 set Month=%Month:~1,1%
if %Month% LEQ 2 (
set /a Year-=1
set /a Month+=12
)
set /a Month+=1
set /a A=%Year%/100
set /a B=2-%A%+%A%/4
set /a C=36525*%Year%/100
set /a D=306001*%Month%/10000
set /a E=%Day%+1720995+%B%
set /a Z=%C%+%D%+%E%
exit /b

:Syntax
echo Enter DateCalc Day Month Year Day Month Year
echo ie DateCalc 05 08 2009 05 08 2010
echo Calculate Difference between
echo Date1 and Date2
echo One leading zero is accepted
echo for Day and Month, Year must be
echo be in full. Date not validated.
exit /b


0
Reply to Message Icon

Related Posts

See More


Microsoft Dot net Windows... renaming a part of multip...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File 'Time Since'

batch files www.computing.net/answers/programming/batch-files/2303.html

Batch File-12 hours time format www.computing.net/answers/programming/batch-file12-hours-time-format/16748.html

Batch File runs multiple times www.computing.net/answers/programming/batch-file-runs-multiple-times/16932.html