home bbs files messages ]

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 41,472 of 42,547   
   foxidrive to sean   
   Re: date format & time questions   
   10 Oct 16 05:30:48   
   
   From: foxidrive@server.invalid   
      
   On 9/10/2016 16:15, sean wrote:   
      
   > So I don't really care for the way Windows sets dates and therefore, I   
   > have this set in my scripts:   
   > SET _DATE=%date:~10,4%%date:~4,2%%date:~7,2%   
      
   Microsoft failed badly with date/time as it can change from machine to   
   machine and region to region.   
      
   This is another method:   
      
   @echo off   
   rem The lines below give you reliable variables   
   rem for YY DD MM YYYY HH Min Sec MS in XP Pro and higher.   
   rem They work in any locale/region.   
      
   for /f "tokens=2 delims==" %%a in ('   
       wmic OS Get localdatetime /value') do set "d=%%a"   
   set "YYYY=%d:~0,4%"   & rem four digit year   
   set   "MM=%d:~4,2%"   & rem zero padded two digit month   
   set   "DD=%d:~6,2%"   & rem zero padded two digit day   
   set   "HH=%d:~8,2%"   & rem zero padded two digit hour   
   set  "Min=%d:~10,2%"  & rem zero padded two digit minute   
   set  "Sec=%d:~12,2%"  & rem zero padded two digit second   
   set   "MS=%d:~15,3%"  & rem zero padded three digit   
   set   "YY=%d:~2,2%"   & rem two digit year   
      
   set "datestamp=%YYYY%%MM%%DD%"  & rem 20160719 date format   
   set "timestamp=%HH%%Min%%Sec%"  & rem 135521   hour format   
                                      rem 2016-07-19_13-55-21.335 format   
   set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%.%MS%"   
      
   echo datestamp: "%datestamp%"   
   echo timestamp: "%timestamp%"   
   echo fullstamp: "%fullstamp%"   
      
   pause   
      
   @echo off   
   rem A simpler version   
   for /f "tokens=2 delims==" %%a in ('   
       wmic OS Get localdatetime /value') do set "d=%%a"   
   set "dt=%d:~0,4%-%d:~4,2%-%d:~6,2%_%d:~8,2%-%d:~10,2%-%d:~12,2%"   
   echo date-time: "%dt%"    & rem 2016-07-19_13-55-21.335 format   
   pause   
      
   --- 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