繁体   English   中英

从当前周获取某一天,然后查询该日期

[英]Getting a certain day from the current week then Query that date

我试图从本周的星期一到星期五获取日期。 然后使用这些日期查询我的 mysql 数据库。 但是我当前的代码不起作用。

$monday = date("Y-m-d",strtotime('next monday', strtotime('previous sunday')));
$sql = 
'SELECT *
FROM customers, jobs
WHERE customers.customerid = jobs.customerid AND duedate = "$monday" AND (jobs.status IS NULL OR jobs.status = "2" OR jobs.status = "3" OR jobs.status = "1" OR jobs.status = "5") AND (jobs.jobtype = "a" OR jobs.jobtype = "A" OR jobs.jobtype = "m" OR jobs.jobtype = "M")
ORDER BY duedate, jobtype';

我也尝试过使用此代码

$monday = date( 'Y-m-d', strtotime( 'monday this week' ) );

两种方式都没有显示任何结果。

您也可以使用 dayoftweek()

星期一 = 2

    SELECT *
    FROM customers, jobs
    WHERE customers.customerid = jobs.customerid 
    AND DAYOFWEEK(duedate) =  2 
    AND (jobs.status IS NULL OR jobs.status = "2" 
        OR jobs.status = "3" 
        OR jobs.status = "1" 
        OR jobs.status = "5") 
    AND (jobs.jobtype = "a"
     OR jobs.jobtype = "A" 
     OR jobs.jobtype = "m" 
     OR jobs.jobtype = "M")
    ORDER BY duedate, jobtype

我找到了解决方案。

这一切都在 sql 查询中完成。

                        $sql = 
                        'SELECT *
                        FROM customers, jobs
                        WHERE customers.customerid = jobs.customerid AND DAYOFWEEK(duedate) =  3 AND YEARWEEK(duedate) = YEARWEEK(NOW())
                        AND (jobs.status IS NULL OR jobs.status = "2" OR jobs.status = "3" OR jobs.status = "1" OR jobs.status = "5") 
                        AND (jobs.jobtype = "a" OR jobs.jobtype = "A" OR jobs.jobtype = "m" OR jobs.jobtype = "M")
                        ORDER BY duedate, jobtype';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM