Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have this oneliner, and i ask my friend to run on his PC (he's using Mac)

perl -le "use Date::Manip qw/UnixDate/;print UnixDate('today','%Y-%m- +%d-%H-%M-%S');"
And he got
2011-09-30-00-00-00

I am sure t hours, minutes and seconds are converted incorrectly (he said "00" always returned for %H, %M and %s)

Do you know why ?

Thanks

Replies are listed 'Best First'.
Re: Date::Manip UnixDate, Hours minutes and seconds are not returned correctly
by BrowserUk (Patriarch) on Sep 30, 2011 at 01:33 UTC
    Do you know why ?

    Because 'today' is a day, not a time of day. Try 'now' if you want date and time.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      I ran the command line in Fedora

      [kia@home bin]$ perl -le "use Date::Manip qw/UnixDate/;print UnixDate +('today','%Y-%m-%d-%H-%M-%S');" 2011-09-30-08-39-24

      So different behaviours returned for linux and Mac.

      I tried 'now' in linux, and working, i'll ask my friend to use now, and see the result

      Thank you

        So different behaviours returned for linux and Mac.

        Just a guess. Different versions of D::M?

        perl -MDate::Manip -E"say $Date::Manip::VERSION" 6.25 perl -MDate::Manip=UnixDate -E"say UnixDate('today','%Y-%m-%d-%H-%M-%S +')" 2011-09-30-00-00-00 perl -MDate::Manip=UnixDate -E"say UnixDate('now','%Y-%m-%d-%H-%M-%S') +" 2011-09-30-02-50-27

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The documentation Date::Manip::Changes5to6 is very clear about this:

        The words "today", "tomorrow", and "yesterday" in 5.xx referred to the time now, 24 hours in the future, and 24 hours in the past respectively.

        As of 6.00, these are treated strictly as date strings, so they are the current day, the day before, or the day after at the time 00:00:00.

        The string "now" still refers to the current date and time.