1.

Solve : Time converted in to seconds?

Answer»

Hi all,
I need to use the TIME in seconds (01:01:01=3661), is there is a qualifier that convert the time displayed be %time% in to seconds?
Or is there an other command that do so.

Tnx in ADVANCE,
B.A.you can do your own maths in BATCH, or you using this vbscript snippet (fine tune to your own specs)
Code: [Select]Dim myTime,objArgs,Hr,Min,Sec
Set objArgs = WScript.Arguments
Hr=objArgs(0)
Min=objArgs(1)
Sec=objArgs(2)
myTime = (Hr * 3600) + (Min * 60) + (Sec)
WScript.Echo "Seconds: ",myTime
output:
Code: [Select]C:\vbscript>cscript /nologo convertSeconds.vbs 1 1 1
Seconds: 3661
Quote from: ghostdog74 on July 01, 2007, 03:47:37 AM

you can do your own maths in batch,

If you prefer a batch solution, here's one...

Code: [Select]@echo off
set /a hh=%time:~0,2%
set /a mm=%time:~3,2%
set /a ss=%time:~6,2%
set /a hh*=3600
set /a mm*=60
set /a hh+=mm
set /a hh+=ss
set /a timeseconds=%hh%
echo time %time%, seconds since midnight = %timeseconds%

Or, written more compactly,

Code: [Select]@echo off
set /a hh=%time:~0,2% & set /a mm=%time:~3,2% & set /a ss=%time:~6,2%
set /a hh*=3600 & set /a mm*=60 & set /a hh+=mm & set /a hh+=ss
set /a timeseconds=%hh%

echo time %time%, seconds since midnight = %timeseconds%











Thanks, both off you have been a great help


Discussion

No Comment Found