1.

Solve : Date & Time naming of log files?

Answer»

I have several time and date routines too.

There's VBS, WMIC, Powershell, and even an Ascii Binary


Code: [Select] :: date time using WSH
:: datetime.bat V4
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: 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
::::::::::::::::::::::::::::::::::::::::::::::::::::::::


echo.
pause
echo.


:: date time using WMIC
:: XP Pro and higher
@echo off
for /f "delims=" %%a in ('Wmic Path Win32_LocalTime Get /value ^|Find "="') do (
for /f "tokens=1,* delims==" %%b in ('cmd /c echo %%a') do set "%%b=00%%c")
set DayOfWeek=%DayOfWeek:~2%
set Quarter=%Quarter:~2%
set WeekInMonth=%WeekInMonth:~2%
set Day=%Day:~-2%
set Hour=%Hour:~-2%
set Minute=%Minute:~-2%
set Month=%Month:~-2%
set Second=%Second:~-2%
set Yr=%Year:~4%
set Year=%Year:~2%
set stamp=%year%-%month%-%day%_%hour%-%minute%-%second%
echo %%stamp%% is set to %stamp% (yyyy-mm-dd_hh-mm-ss)

echo.
pause
echo.

:: timestamp YYYYMMDD_HHMMSS
:: date time using WMIC
:: XP Pro and higher
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
echo %dt:~0,8%_%dt:~8,6%

echo.
pause
echo.

:: timestamp YYYY-MM-DD_HH-MM-SS
:: date time using WMIC
:: XP Pro and higher
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
echo %dt:~0,4%-%dt:~4,2%-%dt:~6,2%_%dt:~8,2%-%dt:~10,2%-%dt:~12,2%

echo.
pause
echo.

:: date time with Powershell
@echo off
for /f "tokens=1-6 delims=-" %%a in (
'powershell get-date -uformat "%%Y-%%m-%%d-%%H-%%M-%%S"'
) do (
set year=%%a&set mon=%%b&set day=%%c
set hour=%%d&set min=%%e&set sec=%%f
)
echo %year%-%mon%-%day% %hour%:%min%:%sec%

echo.
pause
echo.

:: date time using an ascii binary
@echo off
:: Code by Herbert Kleebauer
echo [emailprotected]`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>d_t.com
echo 0DxFP,0Xx.t0P,[emailprotected]$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>d_t.com
echo LisqMz`[emailprotected]`[emailprotected]?ogBgGG}G?j_egoNOG?w?`gBLksqgG`w?WgBgG>>d_t.com
echo G}[emailprotected][emailprotected]`LrFuBLyt~vuco{@LuKooD?BFHqrIcP>>d_t.com
echo _sdDxb1T??=?rILO_sdDqx1T??=?rILO_sdDnl1T??=?rILO_sdD`c1T??>>d_t.com
echo =?rILO_sdDgg1T??=?rILO_sdDll1T??=?rILO_sdDrr1T??=??IL?0xxx>>d_t.com
d_t.com>d_t.bat
call d_t.bat
del d_t.com
del d_t.bat
echo century: %_cy%
echo year: %_yr%
echo month: %_mo%
echo day: %_da%
echo hour: %_hh%
echo minute: %_mm%
echo second: %_ss%

echo.
pause
echo.
Quote from: Salmon Trout on July 22, 2012, 01:17:44 AM

You're thinking of Visual Studio.

Well, VB6/VBA, as OPPOSED to VBScript, which doesn't have the Format Function apparently.


Discussion

No Comment Found