Hour in t TIME using batch script

I would lik to get the Hour value alone from a Time stamp ,

TIME = 12:40:48.35 , I would need only the '12' , hw can i do this in a batch script.
FranklinRaj22Asked:
Who is Participating?
 
t0t0Commented:
EXPLANATION 2:

When the hour is between 1 and 9, the system uses a space followed by a single digit as shown in my previous comment.

If you only want a single digit ('8') instead of two digits ('08') when the hour is between 1 and 9, then you can use the following subtle variant:

     hour = %time%              =   8:21:38.91       - get the full system time string
     hour = %hour:~0,2%     =   8                      - extract first 2 digits
     hour = %hour: =%         = 8                        - strip away leading space

     hour = %time%              = 12:21:38.91       - get the full system time string
     hour = %hour:~0,2%     = 12                      - extract first 2 digits
     hour = %hour: =0%       = 12                      - uneffected
0
 
Rey Obrero (Capricorn1)Commented:

Left([Time],Instr([time],":")-1)  ' will give you 12 from the sample posted
0
 
Shift-3Commented:
In a batch script you would extract those characters with %time:~0,2%.

See here for more information on variable substrings.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
t0t0Commented:
Get hour digits from system time:

   set hour=%time%
   set hour=%hour:~0,2%
   set hour=%hour: =0%

(see next comment for expanation)
0
 
t0t0Commented:
EXPLANATION:

     hour = %time%              =   8:21:38.91       - get the full system time string
     hour = %hour:~0,2%     =   8                      - extract first 2 digits
     hour = %hour: =0%       = 08                      - convert spaces to zeros

     hour = %time%              = 12:21:38.91       - get the full system time string
     hour = %hour:~0,2%     = 12                      - extract first 2 digits
     hour = %hour: =0%       = 12                      - convert does not alter result as there are no spaces
0
 
FranklinRaj22Author Commented:
ok
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.