Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by mmartin (Monk)
on Sep 17, 2012 at 19:39 UTC ( #994087=note: print w/ replies, xml ) Need Help??


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

Ok, so I was able to figure this out.

So I used the same exact formula from my OP and did the total seconds into the past minus 'time'.

This was almost exactly what I wanted, but no matter what I put for a length into the past the
output was ALWAYS showing 4 Hours off from what it should have been...


I then realized that I should have been using "localtime()" instead of "gmtime()". I switched them
up and now its working like a charm!!


Here's how to do it if anyone ever gets stuck trying to calculate a Date AND Time into the past:


For Example --> I want "2 Days, 12 Hours, 1 Minute, and 20 Seconds" into the past...

From my Linux CMD Prompt: FYI... The integer '216080' is the total seconds into the past

### This will print the date and Time in a readable format (i.e. mm/dd/yyy hh:mm:ss in 24-Hour Format)...
perl -e 'use POSIX 'strftime'; $_n_days_ago = strftime("%m/%d/%Y %T", localtime( time-216080 )); print "$_n_days_ago\n"'

### Now what I wanted for MY output is (i.e. "$seconds, $minutes, $hours, $mday, $month, $year")
# I wanted it like this so I could get the UNIX Timestamp of that Past Date and Time by using those values from its output...
perl -e 'use POSIX 'strftime'; $_n_days_ago = strftime("%S, %M, %k, %d, %m, %Y", localtime( time-216080 )); print "$_n_days_ago\n"'


Thanks,
Matt



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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994087]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-12-18 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls