MYSQL Unix_timestamp () detailed

Source: Internet
Author: User

MySQL tutorial Unix_timestamp () detailed

If no parameters are invoked, a UNIX timestamp (the number of seconds after the ' 1970-01-01 00:00:00 ' GMT) is returned as an unsigned integer. If you call Unix_timestamp () with date, it returns the value of the parameter as the 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" conversion. If you pass an overflow date to Unix_timestamp (), it will return 0, but be aware that only the basic scope checks will be performed (the year from 1970 to 2037, the month from 01 to 12, and the date from 01 to 31).

Select ' Start_time ', ' End_time ', Unix_timestamp (now ())
From ' Fair_exhibition_info '
Limit 0, 30

start_time int start time end_time int end time Unix_timestamp (now ())
1249314320 1251560723 1253244650
1251820776 1253721578 1253244650
1251827113 1253900715

The Unix_timestamp function converts the date type data in the MySQL database tutorial to an integer in the Unix timestamp form:

Select Unix_timestamp (' 2006-02-28 ') testdate;

The time stamp supposedly obtained should be used directly for functions such as the date () of the PHP tutorial. But the strange thing is:

echo Date ("y-m-d", $testdate);

The displayed date is a day shorter than the actual date of the database,

Add the eight hours back (Unix_timestamp (' 2006-02-28 ' + interval 8 hour), or discard the Unix_timestamp function and get the MySQL date string directly after the Strtotime () function to The string is translated into a real local timestamp.

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.