Batch command date and time in file name Ask Question. Asked 10 years, 3 months ago. Active 9 months ago. Viewed k times. I guess my issue will extend to the first nine days, first 9 months, etc. Improve this question. Ross Ridge Raj More Raj More I ended up using yours for a daily task, all the answers were far messier. Add a comment.
Active Oldest Votes. Improve this answer. Gerold Broser Stephan Stephan Stephan Do you know how to do this to get the "Date Modified" of a file in a similar format? Logan: I didn't until now, but I found a solution. See my edit. Show 5 more comments. Alex K. That's why I prefer the wmic solution see my answer to this question — Stephan.
Community Bot 1 1 1 silver badge. WxGuy WxGuy 2 2 silver badges 6 6 bronze badges. It is a pity that you cannot chain the transforms. Wow realy cool and short solution. I didn know that you can replace digit in env variables lik this :D — Radon It's a complete nightmare for a BAT programmer. Fortunately, there is an alternative. Works Great — Thanks Reply.
Merlinox on May 19, am. WonderWorker on March 3, am. Jody L Meyer on February 17, pm. Thank you! It works great for me! Eric on September 12, am. Thanks so much for this, tested on win10 pro and it works perfectly. Keith on June 21, pm. Ash on March 27, pm.
Eder Silva on March 6, pm. SCS on March 6, pm. Thank you very much, was very helpful, BUT: — you should mention that the date and time string is depending on the format at the local settings of windows. Learn how your comment data is processed. Checking the date format I made a simple batch script that will just return the current date and under it write some numbers. Here is English US date format: Here is another example of the changed local settings.
Here is an example of the folders the ClamAV quarantine folder sorted by date in their name: We can now see when we caught some viruses in an e-mail. When we analyze this date string, we will see that we need to extract: Four characters between positions 10 and 13 for a year value Two characters between positions 4 and 5 for a month And two characters between positions 7 and 8 for a day Extracting interesting parts Now that we know what we need to extract, we can use this to write our batch file.
Collecting all this together We will now collect all three separated values together and then we can form forth variable TODAY. Stay tuned. Rate this:. Like this: Like Loading How to check the password expiration date? Cheers, Srdjan Like Like. This method is fine, although the returned values depend on the regional […] Like Like. Leave a Reply Cancel reply Enter your comment here Fill in your details below or click an icon to log in:.
Email required Address never made public. Name required. Follow Following. Sign me up. Already have a WordPress. Log in now. The date and time in DOS Scripting have the following two basic commands for retrieving the date and time of the system. Following are some implementations which can be used to get the date and time in different formats. Skip to content. Batch Script Tutorial Batch file create text file with date and time.
0コメント