Timestamp and date Conversion

Source: Internet
Author: User
Unix_timestamp (), Unix_timestamp (date)
If no parameter is called, returns a Unix timestamp (the number of seconds after the ' 1970-01-01 00:00:00 ' GMT) as an unsigned integer. If you call Unix_timestamp () with date, it returns the value of the parameter in the form of a number of seconds after the ' 1970-01-01 00:00:00 ' GMT. Date can be a date string, a DateTime string, a timestamp, or a number in the YYMMDD or YYYMMDD format of a local time.

Mysql> SELECT Unix_timestamp ();    -882226357    mysql> SELECT unix_timestamp (' 1997-10-04 22:23:00 ');    875996580

When Unix_timestamp is used in the timestamp column, the function returns the internal timestamp value directly without any implied "string-to-unix-timestamp" conversions. If you pass an overflow date to Unix_timestamp (), it will return 0, but be aware that only the basic range check will be fulfilled (the year is from 1970 to 2037, the month is from 01 to 12, and the date is from 01 to 31).
Example of the conversion of timestamps and times under PHP:
PHP Code

$timestamp = 1210003200;  $datetime = Date (' y-m-d h:i:s ', $timestamp);  echo "The time stamp represents the time:", $datetime, "<br>\n";  echo "Back to timestamp from this time:", Strtotime ($datetime), "<br>\n";

Example of a time-stamp conversion under MySQL:

SQL Code

Select From_unixtime (1210003200) datetime, Unix_timestamp (From_unixtime (1210003200)) timestamp;
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.