Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

batch files - date time 1

Status
Not open for further replies.

newbie345

Programmer
Apr 5, 2003
3
US
I am trying to figure out how to generate a 24hour date time stamp on my backed up file? I am using WinXP.

code:

rem Start1

for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set d=%%k"-"%%i"-"%%j"-"

for /F "tokens=1,2,3 delims=:. " %%i in ('time /T') do set t=%%i%%j%%k

cd REM The next line copies the file
copy C:\just C:\bak\d%%t%-just.txt"

REM End1

end code:

This works but the time on it is a 12hour clock and has a or p for am and pm.

Please help!!!
 
This is a control panel setting. Regional settings and Select the time tab.
 
Hi Newbie,

Personally, I like parsing "ECHO.|TIME" because it gives seconds and milliseconds if you want them. It will also return 24hour time even if your time settings state 12hr time:

:: ---EXAMPLE.BAT----
@ECHO OFF
FOR /F "TOKENS=5-8 DELIMS=:. " %%F IN ('ECHO.^|TIME') DO (
SET HR=%%F
SET MN=%%G
SET SC=%%H
SET MS=%%I
)
ECHO Hours=%HR% / Mins=%MN% / Secs=%SC% / Millisec=%MS%
:: ---EXAMPLE.BAT----

pb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top