Hour calculation

How could i figured out the total hours taking the start time which would be created using  print localTime as string
"4/12/2011 10:11:18 AM"
and find the difference in hours from star to end.

start = localTime as string
end = localTime as string
print start + end

results:
"4/11/2011 10:15:18 AM"
"4/13/2011 03:10:18 pM"

wanted result:
"4/11/2011 10:15:18 AM"
"4/13/2011 03:10:18 pM"
"xx:xx:xx hours"

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JokerMartini's picture

Great

Thanks SwordSlayer,
Yeah I was messing around with the timestamp but like you said, it was giving me problems when it would hit midnight.
Thank you for the solution of using dotNet. Ill be sure to credit you for that.

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Swordslayer's picture

No problem,glad to be of some

No problem,glad to be of some assistance.

Swordslayer's picture

If the time range would be

If the time range would be short enough, you could use timeStamp for that, but you'd of course have to take into account that it resets the counter at midnight, among other things.

In your case, the dotnet solution should work the best, something like

fn addDecimalPadding nr =
	nr = if nr < 10 then ("0" + nr as string) else (nr as string)
 
fn dnFormatTime tm =
	addDecimalPadding tm.Hours + ":" +
	addDecimalPadding tm.Minutes + ":" +
	addDecimalPadding tm.Seconds
!REG3XP1!>
start_time = (dotNetClass "System.DateTime").Now
sleep 5
dnFormatTime (((dotNetClass "System.DateTime").Now).Subtract start_time)

EDIT: erase the "!REG3XP1!>" from the code... it's just a glitch

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.