Discussion:
how to format the Date and Time to DDMMYYYYHHMMSS in batch?
(too old to reply)
lok
16 years ago
Permalink
Dear all,

I want to have a batch function which format the date and time to this
string: DDMMYYYYHHMMSS and this function should be independent of the
regional setting.

If you have such code, would you mind please share with me?

Thanks in advance and with greeting.

Cheers!
foxidrive
16 years ago
Permalink
Post by lok
I want to have a batch function which format the date and time to this
string: DDMMYYYYHHMMSS and this function should be independent of the
regional setting.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: This uses Windows Scripting Host to set variables
:: to the current date/time/day/day_number
:: for Win9x/ME/NT/W2K/XP etc
:: Thanks go to Todd Vargo for his scripting
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
set TmpFile="%temp%.\tmp.vbs"
echo> %TmpFile% n=Now
echo>>%TmpFile% With WScript
echo>>%TmpFile% .Echo "set year=" + CStr(Year(n))
echo>>%TmpFile% .Echo "set yr=" + Right(Year(n),2)
echo>>%TmpFile% .Echo "set month="+ Right(100+Month(n),2)
echo>>%TmpFile% .Echo "set day=" + Right(100+Day(n),2)
echo>>%TmpFile% .Echo "set hour=" + Right(100+Hour(n),2)
echo>>%TmpFile% .Echo "set min=" + Right(100+Minute(n),2)
echo>>%TmpFile% .Echo "set sec=" + Right(100+Second(n),2)
echo>>%TmpFile% .Echo "set dow=" + WeekDayName(Weekday(n),1)
echo>>%TmpFile% .Echo "set dow2=" + WeekDayName(Weekday(n))
echo>>%TmpFile% .Echo "set iso=" + CStr(1 + Int(n-2) mod 7)
echo>>%TmpFile% .Echo "set iso2=" + CStr(Weekday(n,2))
echo>>%TmpFile% End With
cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
call "%temp%.\tmp.bat"
del "%temp%.\tmp.bat"
del %TmpFile%
set TmpFile=
set stamp=%year%-%month%-%day%_%hour%.%min%.%sec%


echo The year (YYyy) is "%year%"
echo The year (yy) is "%yr%"
echo The month is "%month%"
echo The day (%dow%) is "%day%"
echo The full weekday name is "%dow2%"
echo.
echo ISO 8601 Day-Of-Week number is "%iso%"
echo.
echo The hour is "%hour%"
echo The minute is "%min%"
echo The second is "%sec%"
echo.

echo The date and time stamp is "%stamp%"
echo.
echo time (hhmmss) (%hour%%min%%sec%)
echo.
echo date A (yyyymmdd) (%year%%month%%day%)
echo date B (mmddyyyy) (%month%%day%%year%)
echo date C (ddmmyyyy) (%day%%month%%year%)
echo.
echo date D [yymmdd] [%yr%%month%%day%]
echo date E [mmddyy] [%month%%day%%yr%]
echo date F [ddmmyy] [%day%%month%%yr%]
:: datetime.bat
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
lok
16 years ago
Permalink
...
it works fine, thanks foxidrive
Dr J R Stockton
16 years ago
Permalink
In alt.msdos.batch.nt message <c6b7a10e-c020-4669-b9f9-***@i18g
2000pro.googlegroups.com>, Thu, 13 Aug 2009 08:27:27, lok
Post by lok
I want to have a batch function whichformatthedateandtimeto this
string: DDMMYYYYHHMMSS and this function should be independent of the
regional setting.
  echo>>%TmpFile% .Echo "set yr="   + Right(Year(n),2)
  echo>>%TmpFile% .Echo "set month="+ Right(100+Month(n),2)
  echo>>%TmpFile% .Echo "set day="  + Right(100+Day(n),2)
it works fine, thanks foxidrive
And so it should. But YYYYMMDDhhmmss is a more sensible format.

FOR YOUR purpose, much of that is not needed.

Instead of the quoted lines, one can use by something like :

echo>>%TmpFile% .Echo "set YMD=" + (Year(n)*1e4 + Month(n)*1e2 + Day(n))

and the hhmmss part can be treated similarly or jointly.

If the leading field may need a leading zero, add an appropriate power
of 10 and use Right() once.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3 6.20 ; WinXP.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
Ted Davis
16 years ago
Permalink
Post by lok
Dear all,
I want to have a batch function which format the date and time to this
string: DDMMYYYYHHMMSS and this function should be independent of the
regional setting.
If you have such code, would you mind please share with me?
Thanks in advance and with greeting.
Cheers!
On my systems, it's
gnudate +%%d%%m%%Y%%H%%M%%S

where gnudate.exe is a renamed copy of DATE.EXE from the GnuWin32
CoreUtils package: <http://gnuwin32.sourceforge.net/packages/coreutils.htm>

Help is --help, not /?

Screen dump of the above batch file (test.cmd):

D:\MyFiles>test

D:\MyFiles>gnudate +%d%m%Y%H%M%S
10082009150302

D:\MyFiles>
--
T.E.D. (***@mst.edu)
Loading...