Ameba Ownd

アプリで簡単、無料ホームページ作成

Windows batch file datetime

2022.01.16 00:41




















So, putting the pieces together, try this as a starting point Peter Mortensen Nesar Nesar 5, 2 2 gold badges 20 20 silver badges 20 20 bronze badges.


Vicky Vicky I'm doing this on my company servers, changing locale is not an option on these servers so I'm fairly safe. Peter O. From the answer above, I have made a ready-to-use function.


Validated with french local settings. Your question seems to be solved, but Ok, perhaps it could be that I'm wrong. You just dated yourself with the comment, old timer. Now read my question one more time and you'll see that I never once mentioned that I'm zipping up any code. To make it clear, I'm archiving incoming files that are used in an ETL process. Yes, you never mentioned what you are zipping, that's why I only guessed. And as SO is much used by coders, I guessed wrongly it could be code.


And yes I'm an old timer but this is only a point of view — jeb. Jonathan Jonathan 3 3 silver badges 16 16 bronze badges. Will this work regardless of any date format customizations, or regional settings, in Windows?


Echo todayDate ; and if you save the script as jsdate. Adding other options to this list of answers. Gerhard Gerhard Marty Marty 6 6 silver badges 6 6 bronze badges. How is this relevant with the question about date and time? Valid question. The OP was concerned about no spaces in a file name but does not say why. This could be for aesthetic reasons.


I pasted your solution on another computer which has a different locale than the one I used to raise my original problem, that's what happened and why it output a wrong format.


The other member actually foresaw a problem I did not actually raise, and thought about something that could eventually turn out to be a problem and I found out myself that it is. So yes your solution did solve the problem I originally posted, there is no doubt about that.


No one can be blamed on this. Thank you for your answer and taking time to try and help me Show 1 more comment. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog.


Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. This is my 2 cents for a datetime string. Then double click it. If there is a 0 in the first 2 digits of the time, Windows ignores the rest of the file name of the LOG file.


I tried the accepted answer and it works pretty well. CS, and the missing 0 on the front was causing parsing problems before 10 am. To get over this hurdle and also allow parsing of most any of the world time formats, I came up with this simple routine that appears to work quite well. The nice thing with this routine is that you pass in the time string as the first parameter and the name of the environment variable you want to contain the time in centiseconds as the second parameter.


For example:. In situations like this use a simple, standard programming approach: Instead of expending a huge effort parsing an unknown entity, simply save the current configuration, reset it to a known state, extract the info and then restore the original state. Use only standard Windows resources. Reg is the console registry editor included with all Windows versions.


Elevated privileges are not required to modify the HKCU key. For reasons I don't understand, resetting the "sShortDate" value takes effect immediately in a console window but resetting the very similar "sTimeFormat" value does NOT take effect until a new console window is opened.


However, the only thing changeable is the delimiter - the digit positions are fixed. Likewise the "HH" time token is supposed to prepend leading zeros but it doesn't. Fortunately, the workarounds are easy. So most of the previous answers did not work for me. If you are not picky about the exact format and just want a timestamp to differentiate the files you can do this:. This should work for most locales.


Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Format date and time in a Windows batch script Ask Question. 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. Note: Above only works on US locale. If you have different Windows locale settings, you will need to modify the script based on your configuration. Locale-independent one liner to get any date format you like.


I use it to generate archive names. Back quote option is needed because PowerShell command line is using single quotes. Stack Overflow for Teams — Collaborate and share knowledge with a private group.


Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 3 months ago. Active 10 months ago. Viewed k times.