On 8/13/07, Ow Mun Heng <[EMAIL PROTECTED]> wrote:
> Been struggling with a new script I'm porting over from bash because
> perl's DBI is much more elegant than my previous usage of sqsh.
>
> I'm having trouble converting from a datetime into a unix epoch
> timestamp.
>
> Under perl, I have no idea how this can be achieved.
> Neither localtime, timelocal or AFAICT, DateTime can achieve this
> easily.

perldoc -f gmtime
then
perldoc Time::Local

Time::Local is based on a Perl 4 library, timelocal.pl, that was
included with Perl 4.036, as suggested by lena. The newer version ie
"use Time::Local" is encouraged.

TIMTOWTDI, but if you're inserting a timestamp (Re: the DBI mention)
into a db^Wpostgresql, just pass the string along.  Postgresql has
some clever parser to convert strings to timestamp. At the expense of
parsing speed, of course.

e.g.
[EMAIL PROTECTED]:~> psql template1
template1=# select '2001-1-1 11:11:12 pm'::timestamp, '1 Jan 2001
23:11'::timestamp;
      timestamp      |      timestamp
---------------------+---------------------
 2001-01-01 23:11:12 | 2001-01-01 23:11:00
(1 row)
template1=# select '2001-1-1 11:11:12 pm'::timestamp + '2
months'::interval - '1 day'::interval;
      ?column?
---------------------
 2001-02-28 23:11:12

I'm not sure if you're storing it into the database as a big integer,
or preserving it as a timestamp, but I really, really suggest you keep
it a real timestamp (aka DATETIME) so you don't have to do nasty leap
year and leap seconds arithmetic on it to, say, select stuff by year.

_______________________________________________
Slugnet mailing list
[email protected]
http://www.lugs.org.sg/mailman/listinfo/slugnet

Reply via email to