I need to get today date in Window *.bat
file. After it I would like to get day, month and year. How can I do this?
I can't use PowerShell
On a Microsoft Windows system, you can obtain the current date using the date /t command (the /t option prevents the command from prompting for a change to the the date) or by using echo %date% to display the contents of the date environment variable.
In modern versions of Windows, the date command accepts a four-digit date, e.g., MM-DD-YYYY. With the /t switch, the date command displays the system date, without prompting for a new one.
The date command displays or sets the system date. It is most commonly used to print the date and time in different formats and calculate future and past dates.
This will give you DD MM YYYY YY HH Min Sec
variables and works on any Windows machine from XP Pro and later.
@echo off for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%" set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%" set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%" echo datestamp: "%datestamp%" echo timestamp: "%timestamp%" echo fullstamp: "%fullstamp%" pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With