Inserting the Current Date and Time (Using a MySQL Function)

INSERT some_table (some_column) VALUES (NOW());

The above snippet of SQL uses a MySQL function (called NOW()) to insert the current date and time into fictional column some_column in fictional table some_table.

When NOW() is called, it returns the current date and time (with a precision of seconds) on the machine on which the MySQL server is running. By default, the function returns the text in a human-friendly format, with spaces and punctuation to help readability (such as 2005-09-04 01:43:37). Run SELECT NOW(); for a sample.

If you would like to have the date and time shown as just a string of numbers (such as 20050904014624), add zero to the value of NOW(). Your statement will look like SELECT NOW()+0;


Many useful functions and operators are included with MySQL that allow you to perform mathematical operations, generate conditional output based on the comparison of a column and a value, and so on. For more information, see the online manual.

MySQL Phrasebook. Essential Code and Commands
MySQL Phrasebook
ISBN: 0672328399
EAN: 2147483647
Year: 2003
Pages: 130

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: