MySQL curdate function in INSERT Statement Example

How to get current date in MySQL? 

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

MySQL curdate() 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 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', curdate());

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 00:00:00

As you can see above, new record is added with current date. You can try and practise more and see how it works on your database.