JSI Tip 7322. How do I determine the number of days that have elapsed since the 1st of January 1970 for a given date?


Date attributes in Active Directory are stored as a large integer that represents the number of seconds elapsed since 00:00:00, January 1, 1970 (UTC).

Ritchie Lawrence has scripted DateToDays.bat, which contains:

@echo off
:: DateToDays %yy% %mm% %dd% days
::
:: By:   Ritchie Lawrence, 2002-09-26. Version 1.0
::
:: Func: Returns the number of days elapsed since 1st January 1970 for a
::       given date. For NT4/2K/XP
::
:: Args: %1 year component used to create days, 2 or 4 digits (by val)
::       %2 month component used to create days, leading zero ok (by val)
::       %3 date of month used to create days, leading zero ok (by val)
::       %4 var to receive number of elapsed days (by ref)
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
endlocal&set %4=%j%
NOTE: See How do I convert the number of days that have elapsed since the 1st of January 1970 to a date?



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish