I want the date to be in a specific format : "MM-DD-YYYY HH:MIN AM/PM"
waiting for the solution.
|
I want the date to be in a specific format : "MM-DD-YYYY HH:MIN AM/PM" waiting for the solution. |
|||
|
|
|
See here for an example of how to get an date time setting that is independent of regional settings. To call the script,
Use a for loop to capture the output if needed. |
|||||||
|
|
Very easy to get the date and time, actually:
I'm assuming local time here. If you need UTC, adapt it accordingly. Your format makes things more complicated. Apologies if I get something wrong here, I'm not familiar with am/pm formats.
We need a few leading zeroes:
Then it's time to assemble the parts:
(Just a random note: Why on earth would you want that timestamp format?) |
|||
|
Unix command line tools are often more powerful than their windows counterparts. But even with Windows you can use some ported command line tools. For example the free UnxTools package:
Here's the download link:
Just take the date.exe from the archive (it's in the subfolder usr\local\wbin) and put it in a folder you also have in your PATH environment. Then you can call the date.exe with parameters like this:
If you want to see all possible formating patterns simply call
Please take care to include the ".exe" extension. If you leave it off then windows will call the internal date command. |
|||
|
|
I use variations of this block of code in nearly every .bat file I write. Use "%datestr%" to get your date string, i.e.: echo %datestr% |
|||
|