Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: question about unix timestamps (epoch)

by sanPerl (Friar)
on Sep 13, 2007 at 14:55 UTC ( #638816=note: print w/ replies, xml ) Need Help??


in reply to question about unix timestamps (epoch)

I think what you want is absolute days between two dates (the way any human would calculate). You can use following code. This will exactly give you 3 days. I have converted localtime to 12:00 am of the day and i am taking difference. It works :-)

use strict; use Time::Local; my $_timestamp1 = '1189669351'; my $_timestamp2 = '1189395751'; my ($sec1,$min1,$hour1,$mday1,$mon1,$year1,$wday1,$yday1,$isdst1) = lo +caltime($_timestamp1); my ($sec2,$min2,$hour2,$mday2,$mon2,$year2,$wday2,$yday2,$isdst2) = lo +caltime($_timestamp2); my $no_of_days = ((timelocal(0,0,0,$mday1,$mon1,$year1,$wday1,$yday1,$ +isdst1) - timelocal(0,0,0,$mday2,$mon2,$year2,$wday2,$yday2,$isdst2)) +/86400); print "$no_of_days\n";


Comment on Re: question about unix timestamps (epoch)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2015-07-02 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (27 votes), past polls