Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 (Parson) 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2018-06-23 22:35 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.