Daily Archives: June 10, 2009

Getting current datetime in ISO format in MySQL

Here is the MySQL function to use to get the current datetime as ISO 8601 format as asked in DarwinCore:


DATE_FORMAT() is obviously a function for formatting date and time, and we are using here %Y for four-digit year, %m for two-digits month, %d for two-digits day and %T for 24-hour time (hh:mm:ss). NOW() gives the current datetime.

And then you get a nice figure like this one:


Note that the same result can be achieved with:

Where CONCAT() is used for concatenating strings, and CURDATE() and CURTIME() give respectively the current date and the current time.

UPDATE: There is now a page for getting the current datetime in different formats. Check the page here: Get the current date in different formats in MySQL.