[Windows] Date and Time in Command Prompt


Description
      File name is very important for information especially when backup files on server to storage in windows environment. we can use some command to add some date and time to filename.

HowTo


echo "Display Current Date and Time Now !!"

ECHO "YEAR :" %date:~-4%
ECHO "DATE :" %date:~4,2%
ECHO "DAY :" %date:~7,2%
ECHO "HOUR :" %time:~0,2%
ECHO "MINUTE :" %time:~3,2%
ECHO "SECOND :" %time:~6,2%

for example :

REN D:\name.log D:\name_%date:~-4%%date:~4,2%%date:~7,2%.log

The result  : name.log => name_20150712.log


you can combine this command with xcopy to get file from other server and add date or time as you like.


hope's this helps :D

Post a Comment

Harap gunakan bahasa yang baik dan sopan, terima kasih