Powered by GeSHi

Source code for datepart.bat

(view source code of datepart.bat as plain text)

  1. @ECHO OFF
  2. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  3. SETLOCAL
  4. IF     "%~1"=="" GOTO Syntax
  5. IF NOT "%~2"=="" GOTO Syntax
  6. SET DatePart=
  7. SET Valid=0
  8. FOR %%A IN (d,h,m,n,q,s,w,ww,y,yyyy) DO IF /I "%~1"=="%%~A" SET Valid=1
  9. IF NOT %Valid%==1 GOTO Syntax
  10.  
  11. > "%~dpn0.vbs" ECHO WScript.Echo DatePart^( "%~1", Now ^)
  12. FOR /F %%A IN ('CSCRIPT //NoLogo "%~dpn0.vbs"') DO SET DatePart=%%A
  13. DEL "%~dpn0.vbs"
  14. ENDLOCAL & SET DatePart=%DatePart%
  15. GOTO:EOF
  16.  
  17. :Syntax
  18. ECHO.
  19. ECHO DatePart.bat,  Version 1.00 for Windows NT 4 and later
  20. ECHO Get the specified numerical part of the current date or time in a variable
  21. ECHO.
  22. ECHO Usage:  DATEPART  option
  23. ECHO.
  24. ECHO Where:  option   can be any of the following values to return:
  25. ECHO                  d        day of the month
  26. ECHO                  h        hour
  27. ECHO                  m        month (number)
  28. ECHO                  n        minutes
  29. ECHO                  q        quarter
  30. ECHO                  s        seconds
  31. ECHO                  w        weekday (number)
  32. ECHO                  ww       week of year
  33. ECHO                  y        day of year
  34. ECHO                  yyyy     year
  35. ECHO.
  36. ECHO Note:   The requested value is returned as environment variable DatePart.
  37. ECHO.
  38. ECHO Written by Rob van der Woude
  39. ECHO http://www.robvanderwoude.com
  40. IF "%OS%"=="Windows_NT" ENDLOCAL
  41.