Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Epoch Day Question. Also, EzDate vs DateTime

by tphyahoo (Vicar)
on Aug 03, 2006 at 14:13 UTC ( #565458=perlquestion: print w/ replies, xml ) Need Help??
tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:

I have a bunch of dates attached to trending information (widgets purchased), and I need to transform them into numbers so that I can do a valid comparison to detect trends.

(See Calculating your basic $constant, $slope, and $error terms for a time series distribution if you're curious, although the specifics don't really matter for this particular question)

To sum it up, I think I need a way to get an "Epoch Day" from a date.

It seems like Date::EzDate does this. However, I'm used to using DateTime, and feel a little silly making the switch for such a seemingly niggly little thing. So, before I start learning and using EzDate, is there a way to accomplish the same thing in a simple way using DateTime?

This also seems like an opportune venue to ask monks who have used both modules if they are aware of any issues / advantages, with either. I have to say, until now, DateTime has served me well. And it appears to have more name recognition, and is being actively maintained. (EzDate hasn't had any changes since 2003... but maybe that just means it works really darned well?) Anyway, I am sure EzDate has its fans as well.

Thanks for your help!

UPDATE: Come to think of it, I'm pretty sure this can be done with DateTime, which comes with *at least* a function to fetch number of epoch seconds. So, could transform this into days using arithmetic I suppose... working this through...

Comment on Epoch Day Question. Also, EzDate vs DateTime
Re: Epoch Day Question. Also, EzDate vs DateTime
by Fletch (Chancellor) on Aug 03, 2006 at 14:21 UTC

    Why not just use YYYYMMDD as the number?

    And never heard of EzDate before. We use (a subclassed version of) DateTime for most things at work (well, in new code; there's still lots of other Date::Calc and Date::Manip stuff strewn hither and yon).

    Update: Oop, you're right. I didn't think about the edge cases of YYYY0131 being followed by YYYY0201.

      The reason I want an epoch date is for normalizing.

      Dec 31 1999 and Jan 1 2000 are just one day away, so there data should appear as neighbors on the graph, or statistics analysis, or whatever.

      Changing a date into an epoch day seemed to me the simplest way to do this. Each day gets a unique integer, and neighbor days are always neighbors... just works.

Re: Epoch Day Question. Also, EzDate vs DateTime
by Limbic~Region (Chancellor) on Aug 03, 2006 at 14:25 UTC
    tphyahoo,
    If your dates are well formed and consistent then a regex and Time::Local should be all you need. While that will convert to seconds since epoch, it is a number and calculations are easy to convert back into units such as days, weeks, and years. There are plenty of other modules that offer functions for performing calculations on dates but I prefer this one.

    Cheers - L~R

Re: Epoch Day Question. Also, EzDate vs DateTime
by Tanktalus (Canon) on Aug 03, 2006 at 15:58 UTC

    Sounds like you have a date, such as "2006-08-03" and need to convert it to something that ensures that "2006-07-31" is 4 times the distance away that "2006-08-02" is. Assuming "day" as the unit, then it would be exactly four away. Sounds like what you want is:

    my $epoch_day = int($datetime_obj->epoch / 24 / 60 / 60);
    Perhaps I'm missing something, though ;-)

      no... you weren't missing anything :) thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://565458]
Approved by planetscape
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 2014-07-12 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls