When using MySQL, you can use the DATE() function to extract the date part from a date or datetime expression.
Here’s how it works.
When returning the current date/time in MySQL, there are a range of functions you can choose from. Most of these are simply synonyms for another function.
However, there are two functions that appear to do the same thing, but are in actual fact, slightly different. The functions I’m referring to are SYSDATE() and NOW().
The MySQL SYSDATE() function returns the current date and time. The value is returned in ‘YYYY-MM-DD HH:MM:SS’ or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context.
This function is similar to NOW() but with a subtle difference. SYSDATE() returns the time at which it executes. NOW() returns the time at which the statement started executing.
In MySQL, the CURRENT_TIME function can be used to return the current time.
This function is actually a synonym for CURTIME() which returns the current time, so you can choose which function you prefer to use.
Both functions return the current time as a value in ‘HH:MM:SS’ or HHMMSS format, depending on whether the function is used in a string or numeric context.
In MySQL, the CURRENT_DATE function can be used to return the current date.
Actually, this function is a synonym for CURDATE() which returns the current date (so you can choose which one you prefer).
Both functions return the current date as a value in ‘YYYY-MM-DD’ or YYYYMMDD format, depending on whether the function is used in a string or numeric context.