On the day of query by php and mysql, this week is queried, and the data instance of this month is queried (the field is a timestamp ).

Source: Internet
Author: User
Tags php and mysql

On the day of query by php and mysql, this week is queried, and the data instance of this month is queried (the field is a timestamp ).

On the day of query by php and mysql, this week is queried to query the data instance of this month (the field is a timestamp)

// Where video is the table name; // createtime is the field; // The database time field is the timestamp /// query Date: $ start = date ('Y-m-d 00:00:00 '); $ end = date ('Y-m-d H: I: s '); SELECT * FROM 'table _ name' WHERE 'time'> = unix_timestamp ('$ start') AND 'time' <= unix_timestamp (' $ end') // query this week: SELECT yearweek ('2014-04-17 15:38:22 ', 1) // The result is 2011 SELECT yearweek ('2014-04-17 15:38:22 ') // The result is 201116 // The reason why the 2nd parameter of yearweek is set to 1 is that the Chinese people are used to taking week 1 as the first day of the week. // Add: // Yes Sunday. SELECT dayofweek ('2014-04-17 15:38:22 ') // the query result is 1, and the day of the week is regarded as the first day of the week. SELECT dayofweek ('2014-04-18 15:38:22 ') // the query result is 2 SELECT weekday ('2014-04-17 15:38:22') // the query result is 6, SELECT weekday ('2014-04-18 15:38:22 ') // the query result is 0. // Therefore, we recommend that you use weekday to obtain the query result + 1, it is more in line with Chinese habits. SELECT * FROM 'table _ name' where yearweek (FROM_UNIXTIME ('time', '% Y-% m-% d % H: % I: % s'), 1) = YEARWEEK (now (), 1) // query this month: $ start = date ('Y-m-01 00:00:00 '); $ end = date ('Y-m-d H: i: s'); SELECT * FROM 'table _ name' WHERE 'time'> = unix_timestamp ('". $ start. "') AND 'time' <= unix_timestamp (' $ end') // query this year: $ start = date ('Y-01-01 00:00:00 '); $ end = date ('Y-m-d H: I: s'); SELECT * FROM 'table _ name' WHERE 'time'> = unix_timestamp ('$ start ') AND 'time' <= unix_timestamp ('$ end ')

Php obtains the start Timestamp and end time of today, yesterday, last week, and this month.

<? Php // <! -- Php obtains the start and end timestamps of today, yesterday, last week, and this month. It mainly uses the php time function mktime (). --> // 1. php obtains the start Timestamp and end timestamp of today $ beginToday = mktime (0, 0, date ('M'), date ('D '), date ('y'); $ endToday = mktime (0, 0, 0, date ('M'), date ('D') + 1, date ('y ')) -1; echo $ beginToday. '---'. $ endToday; echo '<br/>'; // 2. php obtains the start and end timestamps of yesterday. $ beginYesterday = mktime (, 0, 0, date ('M'), date ('D')-1, date ('y'); $ endYesterday = mktime (0, 0, date ('M '), date ('D'), date ('y')-1; echo $ beginYesterday. '---'. $ endYesterday; echo '<br/>'; // 3. php obtains Last week's start Timestamp and end timestamp $ beginLastweek = mktime (0, 0, date ('M'), date ('D')-date ('W ') + 1-7, date ('y'); $ endLastweek = mktime (23, 59, 59, date ('M'), date ('D ') -date ('W') + 7-7, date ('y'); echo $ beginLastweek. '---'. $ endLastweek; echo '<br/>'; // 4. php obtains the start and end timestamps of the month. $ beginThismonth = mktime (, 0, 0, date ('M'), 1, date ('y'); $ endThismonth = mktime (, 59, 59, date ('M'), date ('T '), date ('y'); echo $ beginThismonth. '---'. $ endThismonth; echo '<br/>'; // PHP mktime () function is used to return the Unix timestamp of a date. // Syntax: mktime (hour, minute, second, month, day, year, is_dst) /// parameter description // hour is optional. The specified hour. // Optional. Minutes. // Second is optional. Specified seconds. // Month is optional. Indicates the month in number. // Day is optional. Specified day. // Year is optional. Specified year. In some systems, the valid value ranges from 1901 to 2038. However, this restriction does not exist in PHP 5. // Is_dst is optional. If the time is in the daylight saving time (DST) period, it is set to 1; otherwise, it is set to 0. If it is unknown, it is set to-1. // The is_dst parameter has been deprecated since 5.1.0. Therefore, the new time zone processing feature should be used. The parameter always represents the GMT date, so is_dst has no effect on the result. //// The parameters can be left empty from right to left. The blank parameters are set to the corresponding GMT value. Echo (date ("M-d-Y", mktime (2002,); // The output result is as follows: // Jan-05-

On the day of the above php and mysql query, this week, the query of the data instance for this month (the field is a timestamp) is all the content shared by the editor, I hope to give you a reference, we also hope that you can support the customer's home.

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.