Strange behavior of "date" command

I am observing what appears to be strange behavior in the “date” command. “date” displays today correctly and will accept --date input. However, if I restrict the output using the “+%” operator I get strange results.

freda@localhost.heavy1] ~ $ date
Wed 12 Feb 12:58:28 MST 2025
freda@localhost.heavy1] ~ $ date --date sunday
Sun 16 Feb 00:00:00 MST 2025
freda@localhost.heavy1] ~ $
 
freda@localhost.heavy1] ~ $ date
Wed 12 Feb 12:58:28 MST 2025
freda@localhost.heavy1] ~ $
freda@localhost.heavy1] ~ $ date --date sunday +%u
7
freda@localhost.heavy1] ~ $ date --date sunday +%w
0
freda@localhost.heavy1] ~ $ date +%u
3
freda@localhost.heavy1] ~ $ date +%w
3
freda@localhost.heavy1] ~ $

From the man date command

FORMAT controls the output.  Interpreted sequences are:
.
.
%u     day of week (1..7); 1 is Monday
.
.
%w     day of week (0..6); 0 is Sunday

Is this just me or have I found a real misbehavior?

No, this looks right to me.

On Wednesday, both values will show a day-of-week value of 3. Mon-Tues-Weds (1-2-3) and Sun-Mon-Tues-Weds (0-1-2-3).

The only different value is whether Sunday is 0 or 7.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.