- 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 ("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 "2 days a week four hours two seconds later:", Date ("Y-m-d g:h:s", Strtotime ("+1 Week 2 Day 4 hours 2 Seconds")), "
";
- echo "Next week Four:", Date ("Y-m-d", Strtotime ("next Thursday")), "
";
- echo "Previous Monday:". Date ("Y-m-d", Strtotime ("Last Monday")). "
";
- echo "One months ago:". Date ("Y-m-d", Strtotime ("Last month"). "
";
- echo "One months later:". Date ("Y-m-d", Strtotime ("+1 Month")). "
";
- echo "Ten years later:". Date ("Y-m-d", Strtotime ("+10 Year")). "
";
Copy Code2,mysql date operation, query by date and time
- #mysql查询今天, yesterday, 7 days, nearly 30 days, this month, last month data
- #今天
- SELECT * FROM table name where To_days (Time field name) = To_days (now ());
- #昨天
- SELECT * FROM table name WHERE to_days (now ()) –to_days (Time field name) <= 1
- #7天
- SELECT * FROM table name where Date_sub (Curdate (), INTERVAL 7 day) <= Date (Time field name)
- #近30天
- SELECT * FROM table name where Date_sub (Curdate (), INTERVAL Day) <= Date (Time field name)
- #本月
- SELECT * FROM table name WHERE date_format (Time field name, '%y%m ') = Date_format (Curdate (), '%y%m ')
- #上一月
- SELECT * FROM table name WHERE Period_diff (Date_format (now (), '%y%m '), Date_format (Time field name, '%y%m ')) =1
Copy Code |