in reply to Use 'strftime' to calculate a date/time in the Past.

I've tried a couple different ways using a similar formatted command but it's not giving what I need. Could anyone tell me if this is possible using the functions above?

Its possible, show what you tried

  • Comment on Re: Use 'strftime' to calculate a date/time in the Past.

Replies are listed 'Best First'.
Re^2: Use 'strftime' to calculate a date/time in the Past.
by mmartin (Monk) on Sep 18, 2012 at 17:33 UTC
    Hey Anonymous Monk, thanks for the reply...

    Sorry I forget exactly how the command looked I was asking about at that point... But I was able to get this working!!
    And I was able to make it a little better then what I had posted at the end of this thread that I had my "resolution"
    written in.


    What I was doing was I had included an unneeded/unnecessary step. Here's what I did and what it is NOW...

    FIRST, I had this one Perl command (below):
    *This command would output the Seconds, Minutes, Hours, MDay, Month and Year.

    perl -e 'use POSIX 'strftime'; $_n_days_ago = strftime("%S, %M, %k, %d, %m, %Y", localtime( time-$SECONDS )); print "$_n_days_ago\n"'

    SECOND, I had this other Perl command (below):
    *This command would take the output from the previous Perl command (i.e. $sec, $min, $hr, $mday, etc....) and would use
    those values and feed them into this Perl Command to give me a UNIX Timestamp...


    perl -e 'use Time::Local; print timelocal($sec,$min,$hour,$mday,$month,$year), "\n"'


    Stupidly, not realizing that instead of those 2 commands, all's I needed to do was the 1st Perl Command and use the output
    modifier --> "%s" to print a UNIX Timestamp.... Duhhh me!!

    Here's the working Command:

    PAST_TIMESTAMP=$(perl -e 'use POSIX 'strftime'; $_n_days_ago = strftime("%s", localtime(time-$ENV{TOTAL_SECONDS} )); print "$_n_days_ago"')


    Anyway, thanks for all the help/suggestions, very much appreciated!!


    Thanks Again,
    Matt