簡體   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