Formatting the date regardless of regional settings

  • Thread starter Thread starter BigMan
  • Start date Start date
B

BigMan

How can I set a variable to today's date in the format yyyy.mm.dd regardless
of regional settings?
 
BigMan said:
How can I set a variable to today's date in the format yyyy.mm.dd
regardless of regional settings?
Hi

A combined batch/vbs solution creating a date variable in the
format YYYY.MM.DD regardless of the regional settings:


'--------------------8<----------------------
@echo off
echo D = Now : WScript.Echo Year(D) ^& "." ^& _ >%tmp%\today.vbs
echo Right(100+Month(D),2) ^& "." ^& Right(100+Day(D),2) >>%tmp%\today.vbs

for /f "tokens=1" %%a in (
'cscript.exe //Nologo %tmp%\today.vbs') do set today=%%a

del %tmp%\today.vbs
echo Todays date: %today%
'--------------------8<----------------------


Any reason you use . as separator?

If you look at the ISO 8601 standard, the preferred date field
separator is '-' (YYYYMMDD is also ISO compliant).

More about ISO 8601 here:

http://www.merlyn.demon.co.uk/datefmts.htm#Writ
http://www.cl.cam.ac.uk/~mgk25/iso-time.html
http://www.iso.org/iso/en/prods-services/popstds/datesandtime.html
 
How can I set a variable to today's date in the format yyyy.mm.dd regardless
of regional settings?
Use #LogDate (which is always yyyymmdd).

For more info and color-keyed examples, see
(http://TheSystemGuard.com/MtCmds/GetValue/GetLogDate.htm)

*******

..GetLogDate is part of the FREE Advanced Command Library.

(http://ntlib.com)

-tsg

/-----------------+---------------+----------------------\
| COMPATIBILITY | CLARITY | SPEED |
| Write code ONCE | Make it clear | THEN...Make it fast! |
\-----------------+---------------+----------------------/
400+ command-line resources using ONLY native NT commands!
(http://TheSystemGuard.com/default.asp#MasterCommandList)
 
Back
Top