1

I am having a time format in a variable as:

TIME 12/12/12

I need to reformat it into 12-12-12. How I can do it in a Tcl (Expect) script?

My script is test.tcl:

#!/usr/bin/expect

set time "12/12/12"

# here I need something so time will become 12-12-12
puts $time 
# I will get 12-12-12 
2
  • Have we forgotten the lessons of Y2K already? 'Tis sad... Commented Dec 24, 2012 at 18:51
  • 1
    12/12/12 is not a very good example. Do you mean mm/dd/yy -> yy-mm-dd? Commented Dec 24, 2012 at 20:07

3 Answers 3

3

Tcl has a built in string function for this:

string map {/ -} $time

You'll have to either put this after puts or in a new set:

puts [string map {/ -} $time] or set time [string map {/ -} $time]

Sign up to request clarification or add additional context in comments.

1 Comment

:its not changing , giving same while printing the $time after above statement
3
set time [clock format [clock scan $time] -format "%y-%m-%d"]

Comments

0

This works for me: set datestring [clock format [clock seconds] -format "%y%m%d" -gmt true] good luck

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.