Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch    |    Fun with MS-DOS batch files    |    42,547 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 40,547 of 42,547    |
|    foxidrive to Tom Lavedas    |
|    Re: Changing date output format to yyyy.    |
|    07 Nov 12 01:46:21    |
   
   From: not@this.address.invalid   
      
   On 07/11/2012 01:08, Tom Lavedas wrote:   
      
   > I prefer using VBS for date manipulations, since it tends to take fewer   
   steps. For example, the following little hybrid batch/VBS approach   
   generalizes the use of snippets of VBS code ...   
   >   
   > @echo off   
   > if [%2]==[] %0 Result=%1   
   > echo wsh.Echo eval("%~2") > "%temp%\_tmp.vbs"   
   > for /F "delims=" %%a in (   
   > 'cscript //nologo "%temp%\_tmp.vbs"') do set %1=%%a   
   > del %temp%\_tmp.vbs   
   >   
   > It could be used to return the day of the week text thus ...   
   >   
   > call runvbs dow="WeekdayName(weekday(date),true)"   
   > echo Day of the week is %dow%   
      
      
   That's a neat little tool, Tom, I can see the uses it can be handy for.    
   Unfortunately VBS doesn't flow   
   off the tongue for me - I always meant to get a little more acquainted with it   
   but I still mostly hack   
   around with other peoples solutions.   
      
   Here's the VBS solution for date/time stamps based on Todd's work.   
   If the OP is using XP Home then he won't have Wmic by default - so I'll add it   
   here.   
      
      
      
    :: 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   
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
      
      
      
   --   
   foxi   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca