How to use the MySQL timestamp function?
There are several built-in functions in MySQL that can be used to handle timestamps.
- The UNIX_TIMESTAMP() function converts a date or date/time expression into a UNIX timestamp, which is the number of seconds since January 1, 1970 to the given date.
SELECT the UNIX timestamp for ‘2021-01-01 00:00:00’;
- FROM_UNIXTIME() function: converts a UNIX timestamp into a date or datetime format.
Example: Retrieve the date and time from Unix timestamp 1609459200.
- The NOW() function: returns the current date and time.
Choose the current date and time.
- The CURDATE() function returns the present date.
Show the current date.
- CURTIME() function: returns the current time.
Choose the current time now.
These functions can be used in MySQL to manipulate timestamp data, and they can be formatted and converted as needed.