Home > Backend Development > PHP Tutorial > My summer holiday English composition php&mysql date operation notes

My summer holiday English composition php&mysql date operation notes

WBOY
Release: 2016-07-29 08:48:07
Original
1038 people have browsed it

In time comparison queries, int is significantly more efficient. See the auspicious article at http://www.jb51.net/article/29767.htm
But when working on a project or directly viewing data in the database, it is obvious that this int is very obvious at first sight. For example, we want to
view a user Registration time:
select reg_time from t_xx_users where user_id=1;
The return value at this time is an int value, and the specific time cannot be seen intuitively, so this time involves the conversion problem of datetime and int,
There is also the date of PHP and time also involve corresponding conversions. A brief summary of this article:
(1)php
int value:
time(): returns the number of seconds since the Unix epoch (January 1, 1970, 00:00:00 Greenwich Mean Time) to the current time.
We want to get the number of seconds from January 1, 1970 to 2012-2-10, which can be achieved through strtotime(): that is: strtotime('2012-2-10');
date value:
string date ( string format [, int timestamp] )
For example: directly date() returns the current time, of course we can specify its format: for example date('Y-m-d', strtotime('2012-2-10') );
Time operations:
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
select dayofmonth('2012-2- 2');Returns the day of the month
select dayofyear('2012-2-2');Returns the day of the 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 has introduced my summer holiday English composition php&mysql date operation notes, including the content of my summer holiday English composition. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template