• what's the best way to get today at 00:00:00?

    From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Thu Jul 24 08:02:45 2025
    From Newsgroup: comp.lang.tcl

    I have a function that returns today's date/time at 00:00:00, e.g., 2025-07-24T00:00:00, returned as seconds:

    proc start_of_day {} {
    clock scan "[clock format now -format %Y]-[clock format now \
    -format %m]-[clock format now -format %d]" -format "%Y-%m-%d"
    }

    Is there a better way?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From rene@user4652@newsgrouper.org.invalid to comp.lang.tcl on Thu Jul 24 08:24:53 2025
    From Newsgroup: comp.lang.tcl


    Mark Summerfield <m.n.summerfield@gmail.com> posted:

    I have a function that returns today's date/time at 00:00:00, e.g., 2025-07-24T00:00:00, returned as seconds:

    proc start_of_day {} {
    clock scan "[clock format now -format %Y]-[clock format now \
    -format %m]-[clock format now -format %d]" -format "%Y-%m-%d"
    }

    Is there a better way?
    clock scan [clock format now -format %Y-%m-%d]
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From EvoTcl@evotcl@evotcl.com to comp.lang.tcl on Thu Jul 24 02:19:17 2025
    From Newsgroup: comp.lang.tcl

    On 7/24/25 01:02, Mark Summerfield wrote:

    Is there a better way?

    What about [clock scan "today 00:00:00"] ?

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Rich@rich@example.invalid to comp.lang.tcl on Thu Jul 24 13:55:59 2025
    From Newsgroup: comp.lang.tcl

    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    I have a function that returns today's date/time at 00:00:00, e.g., 2025-07-24T00:00:00, returned as seconds:

    proc start_of_day {} {
    clock scan "[clock format now -format %Y]-[clock format now \
    -format %m]-[clock format now -format %d]" -format "%Y-%m-%d"
    }

    Is there a better way?

    proc start_of_day {} {
    return [clock format [clock seconds] -format "%Y-%m-%dT00:00:00"]
    }
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Rich@rich@example.invalid to comp.lang.tcl on Thu Jul 24 16:31:10 2025
    From Newsgroup: comp.lang.tcl

    Rich <rich@example.invalid> wrote:
    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    I have a function that returns today's date/time at 00:00:00, e.g.,
    2025-07-24T00:00:00, returned as seconds:

    proc start_of_day {} {
    clock scan "[clock format now -format %Y]-[clock format now \
    -format %m]-[clock format now -format %d]" -format "%Y-%m-%d"
    }

    Is there a better way?

    proc start_of_day {} {
    return [clock format [clock seconds] -format "%Y-%m-%dT00:00:00"]
    }

    Ah, missed the "returned as seconds".

    proc start_of_day {} {
    return [clock scan [clock format [clock seconds] -format "%Y-%m-%dT00:00:00"] -format %Y-%m-%dT%H:%M:%S]
    }
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Thu Jul 24 12:48:05 2025
    From Newsgroup: comp.lang.tcl

    On 7/24/2025 4:02 AM, Mark Summerfield wrote:
    I have a function that returns today's date/time at 00:00:00, e.g., 2025-07-24T00:00:00, returned as seconds:

    proc start_of_day {} {
    clock scan "[clock format now -format %Y]-[clock format now \
    -format %m]-[clock format now -format %d]" -format "%Y-%m-%d"
    }

    Is there a better way?

    I am curious why a better way? It doesn't seem that heavy or slow.

    However, you can make it more "robust". It is possible that on a Dec 31,
    2024, you will get 2024-Jan-01T00:00:00 because you are treating 3
    different time points as "now". After the firs call for the year, the
    clock may switch to the next year.


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Thu Jul 24 12:51:39 2025
    From Newsgroup: comp.lang.tcl

    On 7/24/2025 12:48 PM, saito wrote:
    However, you can make it more "robust". It is possible that on a Dec 31, 2024, you will get 2024-Jan-01T00:00:00 because you are treating 3
    different time points as "now".  After the firs call for the year, the clock may switch to the next year.



    Well, it is highly unlikely, with chances being slimmer thank winning
    the mega lottery.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Rich@rich@example.invalid to comp.lang.tcl on Thu Jul 24 20:02:06 2025
    From Newsgroup: comp.lang.tcl

    saito <saitology9@gmail.com> wrote:
    On 7/24/2025 12:48 PM, saito wrote:
    However, you can make it more "robust". It is possible that on a Dec 31,
    2024, you will get 2024-Jan-01T00:00:00 because you are treating 3
    different time points as "now".  After the firs call for the year, the
    clock may switch to the next year.

    Well, it is highly unlikely, with chances being slimmer thank winning
    the mega lottery.

    Sadly, these "highly unlikely" items are just the things to come out of (seemingly) nowhere after the code's been running for years, and then,
    one time, on Dec 31 the planets align "just right" and the process goes "boom".

    Only by then, no one knows why, and possibly, the original author has
    also moved on to elsewhere.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Fri Jul 25 06:38:29 2025
    From Newsgroup: comp.lang.tcl

    On Thu, 24 Jul 2025 02:19:17 -0700, EvoTcl wrote:

    On 7/24/25 01:02, Mark Summerfield wrote:

    Is there a better way?

    What about [clock scan "today 00:00:00"] ?

    Thanks for all the replies; this is the one I used.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Schelte@nospam@wanadoo.nl to comp.lang.tcl on Sat Jul 26 22:28:31 2025
    From Newsgroup: comp.lang.tcl

    On 24/07/2025 11:19, EvoTcl wrote:
    On 7/24/25 01:02, Mark Summerfield wrote:

    Is there a better way?

    What about [clock scan "today 00:00:00"] ?

    This uses free-format scan, which the manual page says is deprecated.
    The non-deprecated version would be: [clock scan 00:00:00 -format %T].
    You can add the -base option if you want something other than today. But
    -base defaults to now, so it is unnecessary for "today".


    Schelte.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Sun Jul 27 08:58:53 2025
    From Newsgroup: comp.lang.tcl

    On Sat, 26 Jul 2025 22:28:31 +0200, Schelte wrote:

    On 24/07/2025 11:19, EvoTcl wrote:
    On 7/24/25 01:02, Mark Summerfield wrote:

    Is there a better way?

    What about [clock scan "today 00:00:00"] ?

    This uses free-format scan, which the manual page says is deprecated.
    The non-deprecated version would be: [clock scan 00:00:00 -format %T].
    You can add the -base option if you want something other than today. But -base defaults to now, so it is unnecessary for "today".


    Schelte.

    Thanks, I'm now using your non-deprecated approach.
    --- Synchronet 3.21a-Linux NewsLink 1.2