in reply to Re: Date Handling in Perl
in thread Date Handling in Perl

Are you using '1 day ago' for month and year too?

Replies are listed 'Best First'.
Re^3: Date Handling in Perl
by joeymac (Acolyte) on Jul 11, 2012 at 19:57 UTC

    From what I've read:

    date -d "1 day ago"

    should be smart enough to know that on the first day of the month, 1 day ago was 30|31 (or 28|29) of LAST month. Also true for January 1 (and knowing it was last month AND last year). I tested like this:

    bash-3.2$ date +%j 193 bash-3.2$ date -d "193 day ago " Sat Dec 31 14:54:22 UTC 2011
    Should this hold true?

      Yes, '1 day ago' affects the full date, not just the day. But you get year, month, and day with separate calls - so if you need to get the day again with '1 day ago', you should also get the month and year again with '1 day ago'.

      You could get them with one system call:

      ($y,$m,$d) = split/\s/,`date "+%Y %M %d"`; ($y,$m,$d) = split/\s/,`date -d "1 day ago" "+%Y %M %d"`;