MySQL now function in INSERT Statement Example

How to get current date and time in MySQL? 

MySQL provides a way to get current date and time using now() function. It can be used in Insert statement, Update statement, Where clause or any where else where current date and time is required.

MySQL now() function in INSERT Statement Example: 

Assume that you have a table 'customer' in your database.

idnameaddressemailcreated
1 Jwalant 123 xyz street jwalanttest@test.com 2013-01-01 05:45:37
2 Piyush 456 abc street piyushtest@test.com 2013-02-01 08:35:34
3 Hiren 789 pqr street hirentest@test.com 2013-03-01 11:42:27

You want to add new customer with current date and time in column 'created'. Use following syntax of sql insert statement with now() function for that case:

          INSERT INTO customers2 (name, address, email, created) 
          VALUES ('Vipul', '344 rfe street', 'vipultest@test.com', now());

Result:

idnameaddressemailcreated
1 Jwalant 123 xyz street jwalanttest@test.com 2013-01-01 05:45:37
2 Piyush 456 abc street piyushtest@test.com 2013-02-01 08:35:34
3 Hiren 789 pqr street hirentest@test.com 2013-03-01 11:42:27
4 Vipul 344 rfe street vipultest@test.com 2013-10-13 16:42:49

As you can see above, new record is added with current date and time.