Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

Comment on Re: NOW SQL portability
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 taking refuge in the Monastery: (11)
As of 2015-11-25 20:19 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (690 votes), past polls