-
- //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 june 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 and 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 "One 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"))."
";
Copy code
2, mysql date Operation, query by date and time
-
- #mysql query today, yesterday, 7 days, last 30 days, this month, last month data
- #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' )
- #Previous month
- SELECT * FROM table name WHERE PERIOD_DIFF( date_format( now( ) , '%Y %m' ) , date_format( time field name, '%Y%m' ) ) =1
Copy code
|