Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:26:37+00:00 2026-06-01T22:26:37+00:00

I am in a bit of dilemma here handling the tcl clock function Here

  • 0

I am in a bit of dilemma here handling the tcl clock function

Here is my code:

set old_date 0

if{ "[clock format [clock scan $old_date] -format {%d %b}] != "[clock format [clock scan $event_date] -format {%d %b}]}
{
    if{$old_date !=0}
    {   
        set myTest($value) $old_date;
        #some other stuff
    }
}
set old_date $event_date

It works(should) in most cases.
But my problem is
[clock format [clock scan $old_date] -format {%d %b}] returns today’s date if $old_date=0.

I know it’s probably returning the right value but I do not want it return today’s date if the value is zero. It kind of messes my comparison logic. I can probably check for an if condition but
Is there something i can do with the clock function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:26:39+00:00Added an answer on June 1, 2026 at 10:26 pm

    The problem is that you’re doing (in effect) [clock scan 0]. The clock scan command will, if all else fails, fall back to trying to parse whatever you throw into it. With a 0, it ends up as deciding it refers to 00:00:00 on the current date. I don’t know if this is a correct parse of that string, but it’s arguably not wrong: it’s a truly horribly denormalized time.

    What would make sense is keeping a timestamp in old_date; that’s the kind of value that clock scan returns. Since you’re looking for a date-level granularity, let’s pick a standard time of the day to represent that day (midday, GMT). Now, we can use the -base and -gmt options to make everything work in our conversion code (put into a little procedure for convenience):

    proc dateStamp {date} {
        clock scan "12:00:00" -base [clock scan $date -gmt 1] -gmt 1
    }
    

    Given that, we can now rewrite the rest of your code:

    set old_date 0
    
    if {$old_date != [dateStamp $event_date] && $old_date != 0} {
        set myTest($value) [clock format $old_date -format "%d %b"]
        #some other stuff
    }
    set old_date [dateStamp $event_date]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of a dilemma here. I have a drupal 7 database
I have a bit of a dilemma here. I have an app that has
I've got a bit of a dilemma with some PHP code. The site I'm
I'm running into a bit of dilemma at the moment in that I need
Where I work we have a little bit of a dilemma... I work on
Bit of a strange question here i know. but i wanted to know if
Bit of a beginner question here: Say I have a block of xml: <root>
Bit confused here, I have an on-demand instance but do I get charged even
I always seem to encounter this dilemma when writing low level code for MCU's.
Bit of an abstract problem here. I'm experimenting with the Domain Model pattern, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.