Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: NOW SQL portability

by rpnoble419 (Pilgrim)
on Dec 22, 2009 at 21:07 UTC ( #813979=note: print w/replies, xml ) Need Help??

in reply to NOW SQL portability

The NOW() function is not part of the ANSI SQL function standard.

Your best solution is to use perl to read the local OS date and time and store the result in your database. I use the Date::Calc Today_and_Now function. This works for basic inserts, but you would need to use the function you described above if you are using a trigger to update your database.

Replies are listed 'Best First'.
Re^2: NOW SQL portability (current_timestamp)
by erix (Vicar) on Dec 22, 2009 at 22:49 UTC

    Yes, CURRENT_TIMESTAMP (without parens) is what the SQL standard (SQL2008) prescribes (and it looks like mysql does actually implement it).

    (In law-abiding systems like postgres, now() and current_timestamp are synonymous)

    However, I don't see any CURRENT_TIMESTAMP in sqlite.


    I now actually tried it: turns out that SQLite does implement current_timestamp after all (without parens).

    DBD::SQLite::VERSION = 1.27

    So, the best solution for the OP: use the standard current_timestamp (in both mysql and sqlite) instead of non-standard now().

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2016-10-23 02:24 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (300 votes). Check out past polls.