Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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
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.

    update:

    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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2014-08-27 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (242 votes), past polls