Determining today while using UTC dates

I have maintained internationalisation, who knows I may travel again one day, of all my dates by setting them with the UTC flag, just as for created and modified. So please consider a due-date or done-date are in UTC.

  • It is easy enough to format these for display as they are converted to local time

However I am getting confused when trying to test if a given date is Today, when Now returns the local time, and my fields contain UTC times. For me at +11 UTC part of the day is the same today and the other part of the day is not.

Does anyone have a code pattern to do this comparison?

  • Keep in mind I want to do this against various date fields so need to pass that in as a parameter and may at some point want to compare other local times with UTC encoded date/time stamps.
  • Part of the problem is some of the documentation is silent on this issue.

Since your stored fields always contain UTC datetime values, you should always use <<now "[UTC]...">> to get the UTC-based current datetime value for comparison purposes, and then only omit the β€œ[UTC]” prefix to convert to local time for display purposes.

1 Like

The trouble is, If I am not wrong, this will always tell me something is today in UTC.

Since I live in the +11 Zone for summer, the first 11 hours of the day will be yesterday, then the rest today.

  • I need to convert both to local time then test if they have the same day

I think I may be able to use a filter/function to format the dates then compare but it needs variables;

  • When I tried to set this up I discovered we can’t use <now [UTC]YYYY0MM0DD> in filters.

I am sure it can be done, and I continue to look, but it keeps confusing me, especially when comparing with now in local time.

For example right now \function local-today() [<now YYYY0MM0DD>] gives me yesterday (UTC)

  • I need this to match now to local-day of a fieldname.

Something seem just wrong;

I think I have a solution but need to check it can be used universally.

\function is.today(fieldname:"created") [all[current]get<fieldname>format:date[YYYY0MM0DD]match<now YYYY0MM0DD>]

* `{{{ [all[current]function[is.today]] }}}` {{{ [all[current]function[is.today]] }}}
* `<<is.today>>` <<is.today>> defaults to created on current tiddler
* `{{{ [all[current]function[is.today],[other-date]] }}}` {{{ [all[current]function[is.today],[other-date]] }}}
* `<<is.today other-date>>` <<is.today other-date>>
* `{{{ [is.today[other-date]] }}}` {{{ [is.today[other-date]] }}}
* `{{{ [is.today[modified]then[changed today]] }}}` {{{ [is.today[modified]then[changed today]] }}}
*  `{{{ [is.today[]then[new today]] }}}` {{{ [is.today[]then[new today]] }}}
  • Returns YYY0MM0DD if there is a match and nothing if not.
  • All operate on current tiddler