Locale: Unable to get correct date (for Sunday of this week)

  • Today’s date
$ LC_TIME="en.GB.UTF8" date --iso-8601
2025-01-12
  • Today’s date (day of the week
$ LC_TIME="en.GB.UTF8" date +%u
7

$ LC_TIME="en.GB.UTF8" date +%a
Sun

Issue

  • Since, week starts from Monday to Sunday, this week monday should be 2025-01-06
$ LC_TIME="en_GB.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13
$ LC_TIME="en_IE.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13
$ LC_TIME="en_IN.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13
$ LC_TIME="en_US.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13
$ LC_TIME="en_DE.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13
$ LC_TIME="en_JP.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13
$ LC_TIME="en_DK.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13
$ LC_TIME="en_CA.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13
$ LC_TIME="en_AU.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13

EDIT

Another observation

I did this today on 2025-01-13 (in Germany)

$ LC_TIME="en_AU.UTF-8" date -d "this-week-sunday" --iso-8601
2025-01-19
$ LC_TIME="en_AU.UTF-8" date -d "last-week-sunday" --iso-8601
2025-01-12
$ LC_TIME="en_AU.UTF-8" date -d "next-week-sunday" --iso-8601
2025-01-26

Issue

So, today it seems to be giving partly correct results. What is wrong from today’s output: if from yesterday’s output this-week-monday was 2025-01-13 so somehow computer was counting Sunday as the first day of the week in every locale (that I showed above). So then "this-week-sunday" should be yesterday and not 2025-01-19 (as shown today).

Summary

Yesterday

$ LC_TIME="en_GB.UTF-8" date -d "this-week-monday" --iso-8601
2025-01-13

Today

env -i bash --norc --noprofile
bash-5.2$ LC_TIME="en_AU.UTF-8" date -d "this-week-sunday" --iso-8601
2025-01-19

Issue: So if yesterday (2025-01-12, Sunday), this-week-monday was 13th then, today this-week-sunday should be yesterday and not 2025-01-19 Why am I getting the wrong date output?

Actually … weeks start on Sunday …

Correction:
in ISO 8601, first day of a week is actually Monday … (ooooppppsss!!! … I apologize)

For the computer the week is Sunday thru Saturday
This week Sunday is today Jan 12.

In the USA. Elsewhere the week usually starts on a Monday according to iso860. This also affects the definition of week numbers where the first week of a year may start in December, or the last day of the last week falls in January. This years week one started on 30 December 2024.

1 Like

What you are saying might be applicable only for locale set to C

Hmmm … this looks like a syntax error to me …

LC_TIME="en.GB.UTF8" date --iso-8601

it should be:

LC_TIME="en_GB.UTF8" date --iso-8601

… might try rewriting it this way:
LC_TIME=“en_GB.UTF8” ; echo $LC_TIME
date --iso-8601 (today)
date -d “this-week-monday” --iso-8601 (this week’s monday)
date -d “last-week-monday” --iso-8601 (last week’s monday)
.
Here is what I get:
LC_TIME=“en_GB.UTF8” ; echo $LC_TIME
en_GB.UTF8
date -d “this-week-monday” --iso-8601
2025-01-13
date -d “last-week-monday” --iso-8601
2025-01-06
date -d “next-week-monday” --iso-8601
2025-01-20

… you should get similar results :slight_smile:

Watch out for curly quotes. It should be LC_TIME="en_GB.UTF8" ; echo $LC_TIME

What is the difference? It is the same as the original post. The output is also same as the original post!

@computersavvy @vekruse @einer Please note the edit.

Answer from: bash - Locale: Unable to get correct date (for Sunday of this week) - Unix & Linux Stack Exchange

For the GNU implementation of date, see info date 'date input' for the description of input format.

Here you have a relative date format where this is ordinal number 0, week a multiplier. So date -d 'this week monday' is the same as date -d monday which takes you to the next Monday (or today if today is a Monday) as this week has no effect as it shifts the time by 0.

FWIW, it’s the same with ast-open’s date (same as in ksh93’s printf %T).

Here instead, you could do:

date -d "-$(( $(date +%u) -1 )) day" +%F

Which shifts the current time backward by a number of days which is the current week day number (1 for Monday, 7 for Sunday) minus 1.