Asked 12 years, 5 months ago. Active 3 months ago. Viewed k times. Improve this question. Community Bot 1 1 1 silver badge. Possible duplicate of How to get current datetime on Windows command line, in a suitable format for using in a filename?
You can replace empty spaces on your datetimef variable, and put 0's instead. Add a comment. Active Oldest Votes. Improve this answer. Nasir Grewal 3 2 2 bronze badges. As note for someone who will come here from Google like me : This is locale dependent, so it may require tweaks to work on non-english Windows! All this can be done in just 2 lines using ordinary string replacement: stackoverflow.
Show 2 more comments. There should be a way to mark this as the solution — Rado. The lorax The lorax. On Windows Server and on Windows 7, this gave me the correct string. Much more elegant than what I've constructed in the past, so thank you! Here is what it gives me in Windows 7 with russian locale.
Current time is T, but the script prints: " Andreas Andreas 4, 8 8 gold badges 42 42 silver badges 51 51 bronze badges. Best answer since it explains how to print the variables instead of forcing some substring that can be different for a lot of people. How do you get the UTC-timezone as well, e. Getting the timezone information on the commandline involves other tools.
Lombard G. Lombard 3, 1 1 gold badge 27 27 silver badges 29 29 bronze badges. OK, substitusion in variables. Now - how to substitute a colon :? Colons aren't valid in filenames. Can you substitute 0 for space, delete the colons, and truncate to 6 characters thus deleting the decimal part in a single statement?
It's not that big of deal if it takes two or three lines. I'm just curious. Not that I know. Please follow-up if you find one! Peter Mortensen AngryHacker AngryHacker Add a comment. Active Oldest Votes.
Improve this answer. Community Bot 1 1 1 silver badge. Chris Chris 7 7 silver badges 10 10 bronze badges. Thanks, I tweaked my file exact same way, the I saw your answer. This will not work across different machines as they may have differing date formats. This worked perfect for me, thank you. Like you, the original answer didn't work.
I learned something about manipulating environment variables in a command window! Bernhard Hofmann Bernhard Hofmann 10k 12 12 gold badges 60 60 silver badges 78 78 bronze badges. Joe Joe k 27 27 gold badges silver badges bronze badges. The second command is close, but I was able to build off of it. Michael Fitzpatrick Michael Fitzpatrick 3 3 gold badges 8 8 silver badges 16 16 bronze badges. This should be the accepted answer, as it is truly locale-independent!
ShoeLace ShoeLace 3, 2 2 gold badges 27 27 silver badges 41 41 bronze badges. This is all awkward and not local settings independent. Exstinctor Dumbulator Exstinctor Dumbulator 31 1 1 bronze badge. Dmitri Farkov Dmitri Farkov 8, 1 1 gold badge 27 27 silver badges 44 44 bronze badges. Andre Miller Andre Miller Version 3. EXE available, use Version 2. EXE from the Resource Kit. BAT was also used in AtFuture.
This batch file returns part of the current date or time on screen. BAT to display the current week number:. BAT too, to display yesterday's, today's and tomorrow's dates in two formats:. The complete windows batch script will look like below.
To test this create a file test. Save the file and execute the script. In this tutorial, you have learned to create directories or filenames based on the current date time in the Windows system. That last example works well apart from the quotation marks around Welcome Here!
It is a very clean and precise code snippet for getting the current timestamp in a DOS Batch file. Thanks again! Initialise it as follows:. The solution above breaks if you change locale. What is wrong? I testing on Win Save my name, email, and website in this browser for the next time I comment.
Facebook Twitter Instagram.
0コメント