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 7825255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:53:43+00:00 2026-06-02T08:53:43+00:00

I am calculating the number of days between two dates(the 2 dates are in

  • 0

I am calculating the number of days between two dates(the 2 dates are in seconds). The following gives me the coorect result but it gives me a negative value.

For example -7.0. I am not sure why..

Also can I remove the decimal point and display?

        set interval [expr { $start_date - $get_date }]
        set days [expr { floor($interval / (60*60*24)) }]
        puts "Start Date: $start_date <br>"
        puts "Stop Date: $get_date <br>"
        puts "Total number of dates betwen 2 days: $days"
  • 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-02T08:53:48+00:00Added an answer on June 2, 2026 at 8:53 am

    You’re subtracting the end (assuming that’s what $get_date is) from the start. Think of it like numbers, where a later date is a bigger number – if you subtract a large number from a small number, you get a negative value, right?

    So you probably just want to reverse the arithmetic:

    set interval [expr { $get_date - $start_date }]
    

    I’ve no idea about the decimal point part, I’m afraid… perhaps (based on this documentation) just:

    set days [expr { int($interval / (60*60*24)) }]
    

    EDIT: As noted in comments, some care is required when it comes to “days” between two events. Do you mean elapsed days, 24 hours per day, or “local” days? Are your input values in local time, UTC, or something else? Could you perhaps use a dedicated date/time library to handle this? (I have no idea whether tcl has such a thing, but I’d expect it to.)

    You should think really carefully about exactly what behaviour you want in what situation, and write tests accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I calculate number of days between two dates: NSDateComponents *datesDiff = [calendar components: NSDayCalendarUnit
I have a SQL statement that determines the number of days between two dates.
I am calculating the number of days between the 'from' and 'to' date. For
Is there any oracle functions which will return the number of days between two
How do I calculate the difference between two dates to display as a number
I found the codes to calculate days difference between two dates here . I
I am calculating the difference between two sql dates, TripStartDate and TripEndDate . If
I would like to calculate the number of months and days between two NSDates.
I am working on Windows 7 OS and calculating the number of days between
Is there any method for calculating the number of days in a month?

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.