devwiki:php

This is an old revision of the document!


PHP and SQL

  • select today data entry
    where DATE(`time_entry`) = CURDATE()
  • select current week data entry with option of week start day
    where YEARWEEK(`time_entry`) = YEARWEEK(CURDATE())
    where YEARWEEK(`time_entry`, 1) = YEARWEEK(CURDATE(), 1)
    • Note: weekofyear return week number, means previous year will return too
      where  WEEKOFYEAR(`time_entry`) = WEEKOFYEAR(NOW());
  • select current month data entry
    where YEAR(`time_entry`) = YEAR(NOW()) AND MONTH(`time_entry`)=MONTH(NOW());
  • select past 24 hr
    where `time_entry`> DATE_SUB(NOW(), INTERVAL 1 DAY)
  • select past 7 days
    where `time_entry`> DATE_SUB(NOW(), INTERVAL 1 WEEK)
  • select past 1 month time
    where `time_entry`> DATE_SUB(NOW(), INTERVAL 1 MONTH)
  • devwiki/php.1623680501.txt.gz
  • Last modified: 2021/06/14 14:21
  • by ying