How to use the MySQL timestamp function?

There are several built-in functions in MySQL that can be used to handle timestamps.

  1. 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’;

  1. FROM_UNIXTIME() function: converts a UNIX timestamp into a date or datetime format.

Example: Retrieve the date and time from Unix timestamp 1609459200.

  1. The NOW() function: returns the current date and time.

Choose the current date and time.

  1. The CURDATE() function returns the present date.

Show the current date.

  1. 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.

Leave a Reply 0

Your email address will not be published. Required fields are marked *