MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Get Day, Month, and Year[Next]: Does a File Contain Some Text?
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Batch Files->Batch File Tips and Tricks->Get File Safe Dates and Times

Get File Safe Dates and Times

At times you will need or wish to use date and time information in file or folder names (logs etc), this is one way:

@echo off
for /F "tokens=1,2,3,4 delims=/ " %%i in ('date /T') do set YYYYMMDDDay=%%l-%%k-%%j (%%i)
for /F "tokens=1,2     delims=:"  %%i in ('time /T') do set hhmm=%%i_%%j

echo YYYYMMDDDay: %YYYYMMDDDay%  (In Australia anyway, we use DD/MM/YYYY)
echo hhmm       : %hhmm%

And this is another which uses the "String Replacement" tip:

echo DATE-SAFE "%date:/=-%" (date env var with "/" replaced by "-")
echo TIME-SAFE "%time::=_%" (time env var with ":" replaced by "_")

You may also wish to have a look at the "Get Day, Month, and Year" section.


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Get Day, Month, and Year[Next]: Does a File Contain Some Text?


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday February 28 2016 at 3:45pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.