PHP date processing, MySQL query by date and time

Source: Internet
Author: User
Date_default_timezone_set ('prc'); // Default Time Zone echo "Today:", date ("Y-m-d", time (), "<br> "; echo "Today:", date ("Y-m-d", strtotime ("18 June 2008"), "<br>"; echo "yesterday :", date ("Y-m-d", strtotime ("-1 day"), "<br>"; echo "Tomorrow :", date ("Y-m-d", strtotime ("+ 1 day"), "<br>"; echo "one week later :", date ("Y-m-d", strtotime ("+ 1 week"), "<br>"; echo "one week, two days, four hours, two seconds later :", date ("Y-m-d G: H: s", strtotime ("+ 1 week 2 days 4 hours 2 seconds"), "<br> "; echo "next Thursday:", date ("Y-m-d", strtotime ("next Thursday"), "<br>"; echo "last Monday: ". date ("Y-m-d", strtotime ("last Monday ")). "<br>"; echo "one month ago :". date ("Y-m-d", strtotime ("last month ")). "<br>"; echo "One month later :". date ("Y-m-d", strtotime ("+ 1 month ")). "<br>"; echo "ten years later :". date ("Y-m-d", strtotime ("+ 10 year ")). "<br> ";

Certificate -----------------------------------------------------------------------------------------------------------------------------------------

 # MySQL queries data today, yesterday, 7, last 30 days, this month, and last month # select * from table name today where to_days (time field name) = to_days (now (); # select * from table name yesterday where to_days (now ()-to_days (time field name) <= 1 #7-day select * from table name where date_sub (curdate (), interval 7 day) <= Date (time field name) # select * from table name in the last 30 days where date_sub (curdate (), interval 30 day) <= Date (time field name) # select * from table name in this month where date_format (time field name, '% Y % m') = date_format (curdate (),' % Y % m') # select * from table name in the previous month where period_diff (date_format (now (), '% Y % m'), date_format (time field name,' % Y % m') = 1 

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.