简体   繁体   中英

How can I append time to this command prompt date command

I am trying to run a .bat file with command prompt to add time to the date.

Currently, I have this code

MOVE...\folder\^"Mytest %DATE:/=-%.csv^"

This produces

..\folder\Mytest Thu 12-06-2012.csv

I want to get

..\folder\Mytest Thu 12-06-2012 21:45.csv

Tried all kinds of things but failed miserably. Help would be greatly appreciated.

This will work:

 %date:/=-% %time:~0,5%.csv

The %time% uses the current time; the :~ means "a substring of", and the 0,5 says "starting at the first character (index 0) and continuing for 5 characters", so the entire thing means "give me the first 5 characters of the output of time ".

Using this at a command prompt:

C:\>echo %date:/=-% %time:~0,5%

outputs

Thu 12-06-2012 18:19

The format you're using is going to cause problems with sorting, though. My advice would be to drop the day of the week portion, and change the date output to CCYY-MM-DD , which will be much more useful when you're trying to find a specific date. You can use this:

echo %date:~10,4%-%date:~4,2%-%date:~7,2% %time:~0,5%

which outputs

2012-12-06 18:33

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM