5

Is there a historical reason why date's %h and %b format codes produce the same output?

$ echo $(date +\%h)
Mar

$ echo $(date +\%b)
Mar

Other redundancies exist in date format codes as well, but this one caught my attention this morning. See also this page.

2
  • Indeed. %h seems the odder of those two choices.
    – wallyk
    Mar 8, 2016 at 19:52
  • My guess is that there were originally two different implementations that used a different format code. For compatibility, both have been retained.
    – Barmar
    Mar 8, 2016 at 20:42

1 Answer 1

1

According to http://linux.die.net/man/3/strftime, %h is in the Single UNIX Specification (denoted by 'SU' below) but %b is not.

%b
The abbreviated month name according to the current locale.

%h
Equivalent to %b. (SU)

That's the only difference I can find. man date/strptime/strftime don't contain this information.

2
  • This is good. Thanks. Reading further on that page I found the rest of the answer. The date function contains these redundancies to conform to various standards. Specific to my question, %b conforms to the ANSI C standard, while, as you noted, %h conforms to the Single UNIX Specification. Thus, for compatibility with various standards, redundancies exist. Additional standards that the various encodings conform to are SVr4, C89, C99, Olson's timezone package, glibc, glibc2, POSIX.1, and POSIX.2. In conjunction with my comment here, I'll give you the checkmark.
    – pjd
    May 31, 2016 at 20:00
  • 1
    For the records, %h was later adopted into the C99 standard. Jul 26, 2021 at 11:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .