Twitter Updates

    follow me on Twitter

    G-AVLN in front of her home

    G-AVLN in front of her home

    Mostly Unix and Linux topics. But flying might get a mention too.

    Monday, October 17, 2005

    The case in date

    Tha date command, one of the eldest tools in Unix has got one quirk that escaped me all those years. As usual with these things, it was a delegate who pointed this out to me, with a wry smile.

    A bit of background first. If you need to extract hour and minutes from the date command, you'd probably use:

    $ date +%H:%M
    14:48

    The little 'inverted polish logic' (is that why they keep telling me these things? ;-) ) is if you try to use the AM/PM indicator, achieved with the 'p' options.

    Try the following:

    $ date +%H:%M\ %p
    14:49 PM

    Then try:

    $ date +%H:%M\ %P
    14:49 pm

    Don't know the background to this, but it does appear a deliberate tease ;-)

    2 comments:

    Clive said...

    The reason is as follows: the %p format comes from the SUS/POSIX, and uses the format specified in the locale (not necessarily upper case). GNU wanted to added another option for lower case, and they choose %P. %P does not exist in standard (non-GNU) versions of date. See also the man pages for strftime(3).

    Alina said...

    Ahh - that explains. Except that both HP and Solaris (just checked their man pages) use the GNU version...

    Blog Archive