- // Php date processing
- Date_default_timezone_set ('prc'); // Default time zone
- Echo "today:", date ("Y-m-d", time ()),"
";
- Echo "today:", date ("Y-m-d", strtotime ("18 Jun 2008 ")),"
";
- Echo "yesterday:", date ("Y-m-d", strtotime ("-1 day ")),"
";
- Echo "tomorrow:", date ("Y-m-d", strtotime ("+ 1 day ")),"
";
- Echo "one week later:", date ("Y-m-d", strtotime ("+ 1 week ")),"
"; // Bbs.it-home.org
- 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 ")),"
";
- Echo "next Thursday:", date ("Y-m-d", strtotime ("next Thursday ")),"
";
- Echo "last Monday:". date ("Y-m-d", strtotime ("last Monday "))."
";
- Echo "a month ago:". date ("Y-m-d", strtotime ("last month "))."
";
- Echo "one month later:". date ("Y-m-d", strtotime ("+ 1 month "))."
";
- Echo "Ten years later:". date ("Y-m-d", strtotime ("+ 10 year "))."
";
2. mysql date operations, query by date and time
- # Mysql Query data today, yesterday, 7 days, last 30 days, this month, and last month
- # Today
- Select * from table name where to_days (time field name) = to_days (now ());
- # Yesterday
- SELECT * FROM table name WHERE TO_DAYS (NOW ()-TO_DAYS (time field name) <= 1
- #7 days
- SELECT * FROM table name where DATE_SUB (CURDATE (), INTERVAL 7 DAY) <= date (time field name)
- # Last 30 days
- SELECT * FROM table name where DATE_SUB (CURDATE (), INTERVAL 30 DAY) <= date (time field name)
- # This Month
- SELECT * FROM table name WHERE DATE_FORMAT (time field name, '% Y % M') = DATE_FORMAT (CURDATE (),' % Y % M ')
- # Last month
- SELECT * FROM table name WHERE PERIOD_DIFF (date_format (now (), '% Y % M'), date_format (time field name,' % Y % M') = 1
|