Link to home
Start Free TrialLog in
Avatar of FranklinRaj22
FranklinRaj22

asked on

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.
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image


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

See here for more information on variable substrings.
Get hour digits from system time:

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

(see next comment for expanation)
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
ASKER CERTIFIED SOLUTION
Avatar of t0t0
t0t0
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FranklinRaj22
FranklinRaj22

ASKER

ok