How MySQL Gets the time stamp function Unix_timestamp

Source: Internet
Author: User

CREATE TRIGGER cus_info_tbl_tr after INSERT on CUS_INFO_TBL
For each ROW
INSERT into Summary_tbl (' school_id ', ' province_id ', ' city_id ', ' Year ', ' Month ', ' Day ', ' hour ', ' minute ', ' first_time ', ' Intdate ') VALUES
(NEW.SCHOOL_ID,
NEW.PROVINCE_ID,
NEW.CITY_ID,
Year (New.date_call),
MONTH (New.date_call),
DayOfMonth (New.date_call),
HOUR (New.date_call),
MINUTE (New.date_call),
New.first_time,
Unix_timestamp (New.date_call) +28800
);
See, in this time stamp and then add 8 hours of seconds on the finish, hehe.

But when I was in Google, I noticed that a lot of brothers reacted Unix_timestamp and PHP mktime the same value, but I have a problem here, and I haven't been able to find out why now.

The code is as follows Copy Code

Unix_timestamp (), Unix_timestamp (date)

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.

Inquire

Application comparison of Unix_timestamp () function in MySQL
Application:

The code is as follows Copy Code

SELECT (

Unix_timestamp (Endtime)-unix_timestamp (startime)
)/31536000year,id,name
Fromtestime
limit0,30


Here we can use

From_unixtime (Unix_timestamp), From_unixtime (Unix_timestamp,format) to format a unix_timestamp () timestamp, which will return ' YYYY-MM-DD HH: The Unix_timestamp parameter of the Mm:ss ' or YYYYMMDDHHMMSS format value is expressed in the form of whether the function is used in a string or in a digital context.

If format is already given, the format of the result depends on the format string. The format can contain the same descriptor as the Date_format () function entry list.

The code is as follows Copy Code

Mysql> Select from_unixtime (875996580);

-> ' 1997-10-04 22:23:00 '

Mysql> Select From_unixtime (875996580) + 0;

-> 19971004222300

Mysql> Select From_unixtime (Unix_timestamp (),

-> '%Y%d%m%h:%i:%s%x ');

-> ' 2003 6th August 06:22:58 2003 '

In PHP: Time ()

Time--Returns the current Unix timestamp

Strtotime () can also convert Unix 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.