How to get Time using Batch Command – Substring


The batch programming can be dated back to DOS era. It is further enhanced on Windows Operating System.

The time command on Windows Command Shell return something like this:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Windows\system32>time
The current time is: 13:29:50.12

Now, if you want to extract the hour value, you can use %TIME:~0,2%. And we can store the value into a variable (set)

@echo off
set Hour=%TIME:~0,2% 
if %Hour% GTR 12 (
    ECHO Afternoon
) else (
    ECHO Morning
)

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
164 words
Last Post: Resharper Helps to Find Bug - Enum Type Not Equal to Null Forever
Next Post: Batch Variable SubString Example - Extract Windows Version

The Permanent URL is: How to get Time using Batch Command – Substring

Leave a Reply