[thelist] Perl & Unix epoch

Hans Zaunere zaunere at yahoo.com
Mon Apr 8 08:29:01 CDT 2002


I'm going to put my two cents worth about using UNIX timestamps.
Personally, they are all I use, and I've never had any problems... in
fact, I've had clean, fast, portable code instead.


> If you want to find the records updated or inserted in the last 24
> hours,
> both suffice. But what if you want to find the records that are
> between
> April 1st, 1990 and April 30th, 1990. If you are using Unix
> TimeStamps,
> what do you do?? Calculate the Unix Timestamp ahead of time and use
> between?

Exactly, which is a lot faster than having MySQL do the laborious task
of date manipulation.

> Grab everything and iterate through the data?

Eeek.

>
> What about adding a year to your "deactivation" date? What if it's a
> leap year?

Doesn't matter.  UNIX timestamp -> human conversion takes care of this
(with PHP's date() function, for example).  All other oddities (leap
seconds, daylight savings, etc) are calculated based on the system's
locale (at least in UNIX).

>
> What if I want to find all the records that were created in April,
> irregardless of Year? What about all records created between 8am and
> 5pm, irregardless of date??

Use a combination of date(), defines for known quantities (ie
SECSINWEEK) and wit.

>
> You are correct in saying use the DB to fetch data. My belief is that
> in
> order to facilitate the searching and fetching of data you use the DB
> Date/Time functions.

All this said, there have been times I've gone with MySQL/Oracle's
internal date functions, although it's been rare.  Useually, it is
where I don't have control over the DB schema to begin with, or with
MySQL's temporary tables where I just want to spit report data out.
Generally, however, using timestamps are much cleaner and faster, IMO.

Hans Z.
New York PHP
http://nyphp.org




__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/



More information about the thelist mailing list