This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Subtracting minutes

Old posts that have not been replied to for several years.
Locked
S
SomeGuy
Voice
Posts: 13
Joined: Sat May 01, 2004 5:25 pm

Subtracting minutes

Post by SomeGuy »

Basically right now I've got a script that a user sets a time/date and a description.

Now 2 hours before the time the bot messages the channel, i got that figured out. As well I got 1 hour before and 1 hour after.

When I try to go and use minutes, the leading 0 causes the first problem, but lets say i have the time set at 2:15, and want to subtract 30 mins from that, how do i get the bot to stop at zero and then continue subtracting down the rest at 59?

Thanks
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Code: Select all

set start_stamp [clock scan "2:15"]
set before_stamp [expr {$start_stamp - (30 * 60 * 60)}]
set before_time [clock format $before_stamp "%H:%M"]
S
SomeGuy
Voice
Posts: 13
Joined: Sat May 01, 2004 5:25 pm

Post by SomeGuy »

Awesome man, thanks alot.

Just so you know, there were a couple errors in that code, but I fixed it and now everything is perfect. It should look like this

Code: Select all

set start_stamp [clock scan "2:15"] 
set before_stamp [expr {$start_stamp - (30 * 60)}] 
set before_time [clock format $before_stamp -format "%H:%M"] 
Just minor errors, you were multiplying 60 twice, I don't know why cuz TCL works in seconds, so 30 mins times 60 secs per min. 30*60.

And you forgot the -format. Minor as well.

Thanks for the help, really improved my script. The way I was trying to do this before was horrible.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

the second * 60 was a brain fart... was thinking of hours to minutes to seconds...
Locked