How to get system time like YYYYMMDD?

  • Thread starter Thread starter BDB
  • Start date Start date
B

BDB

Hi,

How do I get the system time like this:

YYYYMMDD

Can I do this with the date command?

Thanks.
 
Control Panel|Regional Settings|Regional Options|Customize|Date

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| Hi,
|
| How do I get the system time like this:
|
| YYYYMMDD
|
| Can I do this with the date command?
|
| Thanks.
|
|
 
Hi,

Hi,

How do I get the system time like this:

YYYYMMDD

Can I do this with the date command?

I've kept this snippet which I found useful:


The following works for both "dd/mm/yyyy" and "mm/dd/yyyy":

@echo off
@rem NEWSGROUP: microsoft.public.win2000.cmdprompt.admin
@rem SUBJECT : How can i to get the current month in commandline?
@rem WHEN/WHO : Mar 14 2001, 9:05 pm post by Michael (maj0)

:: Tokenise date into dd mm and yy independent of locale
for /f "tokens=2-4 delims=.:/-, " %%i in ("%date%") do (
for /f "tokens=2-4 delims=/-,() skip=1" %%l in ('echo.^|date') do (
set %%l=%%i
set %%m=%%j
set %%n=%%k))


:: Lets see what we got!
for %%i in (dd mm yy) do set %%i


Bye,
Dennis Bareis
 
BDB said:
Hi,

How do I get the system time like this:

YYYYMMDD

Can I do this with the date command?
Hi,

Using a batch file, you could use the code below (that creates a
temporary VBScript file on the fly).


--------------------8<----------------------
@echo off

setlocal
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%
pause
endlocal
--------------------8<----------------------

You can do it with "pure" batch file as well, using e.g the batch date
time functions from Ritchie Lawrence batch library available at
http://www.commandline.co.uk/lib
 
In said:
In microsoft.public.win2000.cmdprompt.admin BDB wrote:
How do I get the system time like this:
YYYYMMDD
Can I do this with the date command?
Control Panel|Regional Settings|Regional Options|Customize|Date

I might suggest setting the options to
YYYY-MM-DD
(quite readable)
then in batch just use it as is or remove the hyphens if needed.
 
BDB said:
How do I get the system time like this:
YYYYMMDD

1} How to get today's date elements into environment variables?
130306 Jul 12 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

All the best, Timo
 
Hi,



I've kept this snippet which I found useful:


The following works for both "dd/mm/yyyy" and "mm/dd/yyyy":

@echo off
@rem NEWSGROUP: microsoft.public.win2000.cmdprompt.admin
@rem SUBJECT : How can i to get the current month in commandline?
@rem WHEN/WHO : Mar 14 2001, 9:05 pm post by Michael (maj0)

:: Tokenise date into dd mm and yy independent of locale
for /f "tokens=2-4 delims=.:/-, " %%i in ("%date%") do (
for /f "tokens=2-4 delims=/-,() skip=1" %%l in ('echo.^|date') do (
set %%l=%%i
set %%m=%%j
set %%n=%%k))


:: Lets see what we got!
for %%i in (dd mm yy) do set %%i


Bye,
Dennis Bareis

Thanks!
 
Back
Top