My summer holiday English composition Php&mysql date Operation Little Note

Source: Internet
Author: User
The efficiency of int is significantly higher when comparing queries with time. Xiang Wen See http://www.jb51.net/article/29767.htm
However, when doing the project or directly in the database to view the data, it is obvious that the int is big, such as we want to
To view a user's registration time:
Select Reg_time from T_xx_users where user_id=1;
This time the return is an int value, can not intuitively see the specific times, so it involves the conversion of datetime and int,
There is also a date and time for PHP to be involved in corresponding conversions. This article summarizes briefly:
(1) PHP
int value:
Time (): is the number of seconds to return from the Unix era (00:00:00 GMT, January 1, 1970) to the current.
The number of seconds we want to get from January 1, 1970 to 2012-2-10 can be achieved by Strtotime (): Strtotime (' 2012-2-10 ');
Date value:
String date (string format [, int timestamp])
For example: direct date () returns the implementation of the current time, of course we can specify his format: for example, date (' y-m-d ', strtotime (' 2012-2-10 '));
Time Operation:
Date (' y-m-d h:i:s ', Strtotime (' +1 Week '));
Date (' y-m-d h:i:s ', Strtotime (' +5 hours '));
Date (' y-m-d h:i:s ', Strtotime (' next Monday));
Date (' y-m-d h:i:s ', Strtotime (' last Sunday '));
Date (' y-m-d h:i:s ', strtotime (' + 1 day ', 12313223));!! See int Strtotime (string time [, int now])
(2) MySQL:
Int->datetime
Select From_unixtime (int_time) from table;
datetime->int;
Select Unix_timestamp (date_time) from table;
Time Operation:
Select DayOfWeek (' 2012-2-2 '); Returns the day of the week one
Select DayOfMonth (' 2012-2-2 '); Returns the day ordinal of January
Select DayOfYear (' 2012-2-2 '); Returns the day ordinal of a year
Similar functions: Month () Day () hour () Week () ...
+ Date_add (Date,interval 2 days);
-Date_sub (Date,interval 2 days);
Time Format:
Date_format (Date,format)
Select Date_format (' 1997-10-04 22:23:00 ', '%W%M%Y ');
Other functions: Time_to_sec () sec_to_time () ...

The above describes my summer holiday English composition Php&mysql date operation, including my summer holiday English composition, I hope that the PHP tutorial interested in a friend helpful.

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