简体   繁体   English

mysql查询获取今天和明天日期

[英]mysql query get today and tommrows date

SELECT
   doctors. fullname,
   dutyroster.date,
   dutyroster.time
FROM
   dutyroster
INNER JOIN doctors ON doctors.docid = dutyroster.docid
WHERE doctors.docid = $doc_id AND
dutyroster.date = DATE(NOW()) AND DATE(NOW())+ INTERVAL 1 DAY
ORDER BY dutyroster.`date`  ASC";

this query is used to find specific doctors information from a table called dutyroster. 此查询用于从称为占空比的表中查找特定的医生信息。 i want to get the docs shedule information for current day and tommrow only.. but this doesnt work. 我想获取当前日期的文档信息并仅进行明天..但这不起作用。

and i made a second one which is also not working since it returns current one and all the next dates also 我做了第二个也不能正常工作,因为它返回当前一个,并且所有下一个日期也

SELECT
    doctors. fullname,
    dutyroster.date,
    dutyroster.time
FROM
    dutyroster
INNER JOIN doctors ON doctors.docid = dutyroster.docid
WHERE doctors.docid = $doc_id AND
DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= dutyroster.date
ORDER BY dutyroster.`date`  ASC"

Instead of 代替

... AND dutyroster.date = DATE(NOW()) AND DATE(NOW())+ INTERVAL 1 DAY

try 尝试

... AND (dutyroster.date = CURDATE() OR 
         dutyroster.date = CURDATE() + INTERVAL 1 DAY))

or in more concise way, as @MarcM suggested 或更简洁的方式,如@MarcM建议

... AND dutyroster.date IN (CURDATE(), CURDATE() + INTERVAL 1 day)

From your first attempt it almost looks like you are trying to program COBOL! 从您的第一次尝试开始,就好像您正在尝试对COBOL进行编程一样! Also, for future reference "this doesn't work" is not a helpful comment. 另外,作为将来参考,“此操作无效”不是有用的评论。 You should say what actually happens. 您应该说出实际情况。

Anyway, try changing your where clause to either: 无论如何,请尝试将where子句更改为:

WHERE doctors.docid = $doc_id AND (dutyroster.date = CURRENT_DATE OR dutyroster.date = CURRENT_DATE + INTERVAL 1 DAY) 在哪里doctors.docid = $ doc_id和(dutyroster.date = CURRENT_DATE或dutyroster.date = CURRENT_DATE +间隔1天)

or: 要么:

WHERE doctors.docid = $doc_id AND dutyroster.date IN (CURRENT_DATE, CURRENT_DATE + INTERVAL 1 DAY)) 在哪里doctors.docid = $ doc_id和dutyroster.date输入(CURRENT_DATE,CURRENT_DATE +间隔1天)

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

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