Php calculates the start and end notes for the current day.

Source: Internet
Author: User
To create an order query interface, you need to retrieve the order for the current day. The data table contains only one order time field, which is saved in the timestamp format. Not in 2010-10-5 format. You can specify two time points for data query. Since there is only one pivot point, we have never done anything similar. When writing SQL queries. At first encountered a small obstacle.

To create an order query interface, you need to retrieve the order for the current day. The data table contains only one order time field, which is saved in the timestamp format. Not in 2010-10-5 format. You can specify two time points for data query. Since there is only one pivot point, we have never done anything similar. When writing SQL queries. At first encountered a small obstacle.

To create an order query interface, you need to retrieve the order for the current day. The data table contains only one order time field, which is saved in the timestamp format. Not in 2010-10-5 format. You can specify two time points for data query. Since there is only one pivot point, we have never done anything similar. When writing SQL queries. At first encountered a small obstacle.

According to my colleagues, they can all be converted to the format. The timestamp stored in the database is converted to this format. The year and day indicate the same day of the same year.

The above method can achieve the goal, but the workload is a little large. The starting point is: The timestamp of the database to be converted is in date format. As a friend reminded me, I thought of another idea: converting it into a unix timestamp for comparison. This makes it easier to write SQL queries. Simple. In the previous method, database functions are not only required for SQL writing. In addition, the php code still needs to be judged on the same year and the same day (the same year is required first; otherwise, the same day does not meet the requirements)

The code written at that time is as follows:

/*
* + -------------------------------
* Calculate the start and end timestamp of the current day to retrieve the data of the current day.
* + ------------------------------
*/

$ Year = date ("Y ");
$ Month = date ("m ");
$ Day = date ("d ");
$ DayBegin = mktime (, 0, $ month, $ day, $ year); // the start time of the day.
$ DayEnd = mktime (, 59, $ month, $ day, $ year); // end time stamp of the current day

$ Query = "SELECT * FROM 'fanli _ info' WHERE insert_time <$ dayEnd AND insert_time> $ dayBegin ";

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.