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.
TIME = 12:40:48.35 , I would need only the '12' , hw can i do this in a batch script.
In a batch script you would extract those characters with %time:~0,2%.
See here for more information on variable substrings.
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)
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok
Left([Time],Instr([time],"