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.

need help: how to do arithmatic operations on strings

Old posts that have not been replied to for several years.
Locked
T
Taiyaki
Voice
Posts: 15
Joined: Mon Nov 18, 2002 4:39 am

need help: how to do arithmatic operations on strings

Post by Taiyaki »

in my script i use the clock function to get me the current date, but I want to add 1 to the date (say it's the 8th today, and I want tomorrow's date, so I add 1 to 8 to make it 9)

Code: Select all

set cdate1 [clock format [clock seconds] -format "%m %d %y"]
append esttime [lindex $cdate1 0]
append esttime "/"
append esttime [expr [lindex $cdate1 1] + 1]
append esttime "/"
append esttime [lindex $cdate1 2]
the expected output would be 02/09/03
the line that's giving me trouble is

Code: Select all

append esttime [expr [lindex $cdate1 1] + 1]
it keeps saying that it's not an octal number or something. Can someone please help? Thanks
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Re: need help: how to do arithmatic operations on strings

Post by egghead »

Taiyaki wrote:in my script i use the clock function to get me the current date, but I want to add 1 to the date (say it's the 8th today, and I want tomorrow's date, so I add 1 to 8 to make it 9)

Code: Select all

set cdate1 [clock format [clock seconds] -format "%m %d %y"]
append esttime [lindex $cdate1 0]
append esttime "/"
append esttime [expr [lindex $cdate1 1] + 1]
append esttime "/"
append esttime [lindex $cdate1 2]
the expected output would be 02/09/03
the line that's giving me trouble is

Code: Select all

append esttime [expr [lindex $cdate1 1] + 1]
it keeps saying that it's not an octal number or something. Can someone please help? Thanks
Maybe it is better to add 24*60*60 ticks to the [clock seconds] and then do the [clock format]?
T
Taiyaki
Voice
Posts: 15
Joined: Mon Nov 18, 2002 4:39 am

Re: need help: how to do arithmatic operations on strings

Post by Taiyaki »

egghead wrote:Maybe it is better to add 24*60*60 ticks to the [clock seconds] and then do the [clock format]?
sorry but I'm a newbie :-? I think what you're trying to say is add 24 hours to my clock before doing the format? That sounds like a great idea, but can you give me the code to do that :lol:

Thanks
T
Taiyaki
Voice
Posts: 15
Joined: Mon Nov 18, 2002 4:39 am

Post by Taiyaki »

n/m I realized what you tried to say when I reviewed the TCL manual pages, lol.

Thanks a lot for your help egghead!!! :D
Locked