Batch file time 24 hour format5/12/2023 ![]() :: this is Regional settings dependant so tweak this according your current settingsįor /f "tokens=1-3 delims=:" %%a in ('echo %time%') do set hhmmsss=%%a%%b%%cįor /f "tokens=1-3 delims=." %%D in ('echo %DATE%') do set yyyymmdd=%%F%%E%%D :: click into target media, Ctrl + V to paste the result But hey, who cares!Ĭmd /c "powershell get-date -format ^"^"|clip" ![]() The downside is the messy locale variable names: 'yy', 'mm' and 'dd'. The quotes yield a token (albeit empty) for the left-hand side of the assignment statement. My locale (PT) was causing errors at one stage in the looping/parsing where stuff like "set =20" was getting executed. To get the code to work sans error msg's to stderr, I had to add the single quotes arount the variable assignments for %%a, %%b and %%c. :: Works on any NT/2k machine independent of regional date off Here's a variant from that works local-independently. I don't want to install additional utilities to achieve this (although I realise there are some that will do nice date formatting). I'm using Windows Server 2003 and Windows XP Professional. Ideally it'd be briefer and have the format mentioned earlier. ![]() I can live with this, but it seems a bit clunky. "d:Program Files7-Zip7z.exe" a -r Code_%_my_datetime%.zip Code Rem Now use the timestamp by in a new ZIP file name. So far I've got this, which on my machine gives me Tue_10_14_2008_230050_91: rem Get the datetime in a format that can go in a filename. I don't really mind about the date format, ideally it'd be yyyy-mm-dd, but anything simple is fine. Is there any easy way I can do this, independent of the regional settings of the machine? bat file that zips up a directory into an archive with the current date and time as part of the name, for example, Code_2257.zip. What's a Windows command line statement(s) I can use to get the current datetime in a format that I can put into a filename? Update: Now that it's 2016 I'd use PowerShell for this unless there's a really compelling backwards-compatible reason for it, particularly because of the regional settings issue with using date.
0 Comments
Leave a Reply. |