fortypoundhead.com

Retrieve System Time within a Batch File

Posted On 2015-07-16 by dwirch
Keywords:
Tags: Scripting Windows Commandline Windows Windows 7 Windows 8
Views: 2715


I've shown you previously how to get the date value from the system in a batch file. You can also grab the time in a similar fashion.

Coupled with the script in the other post, this can be used (for example) to find files that were processed in a certain hour of a particular day. Or, perhaps you could use a bit more processing to say, schedule a task for the current time, one day later. Lots of different possibilities.

Here is the code, by request. As usual, if you have any questions, please feel free to leave it in the comments, or over in the forums.

@echo off

REM ***
REM *** Get Current Time, store in Now. Then use
REM *** string operations to grab Hours, Minutes,
REM *** and seconds, storing each in a variable
REM ***

SET Now=%Time: =0%
SET HH=%Now:~0,2%
SET MM=%Now:~3,2%
SET SS=%Now:~6,2%

REM ***
REM *** Display the output
REM ***

ECHO. Current time = %Now%
ECHO. Hours = %HH%
Echo. Minutes = %MM%
Echo. Seconds = %SS%


About the Author

dwirch has posted a total of 172 articles.

 


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.162.19.123

Before you can post, you need to prove you are human. If you log in, this test goes away.


Beat With A Stick List Returns: By request, BWASL has returned to the site. Free your rage by telling the world about something that really grinds your gears. Add your beating.



Recent Forum Posts

BWASL returns
dwirch posted on May 13, 2017 at about 15:24 in Site News

BWASL returns
dwirch posted on May 13, 2017 at about 8:46 in Site News

Job Spammer: Balashankar Bose Bose
dwirch posted on May 11, 2017 at about 10:05 in Spammers

Job Spammer: Bharti Jigyasi
dwirch posted on May 11, 2017 at about 7:58 in Spammers

List of Shady Characters
dwirch posted on April 25, 2017 at about 16:39 in Webmaster Stuff

Job Spammer: Bilal Uddin
dwirch posted on April 25, 2017 at about 11:00 in Spammers