简体   繁体   English

如何找到今天的日期和从今天开始的X天之间的差异?

[英]How do I find the difference between today's date and X days from today?

Hello all, 大家好,

Having checked out all the possible threads that were presented before I asked my question, I didn't find an answer suitable for VB.net and MySQL. 在我提出问题之前,已经检查了所有可能出现的线程,但没有找到适合VB.net和MySQL的答案。 Most dealt with Android and PHP. 大多数使用Android和PHP。

So I'm trying to run a query against a date field in a table within my MySQL database that finds all the records with a date value that's X number of days from today. 因此,我试图对我的MySQL数据库中的表中的日期字段运行查询,以查找日期值为从今天起X天的所有记录。 How would I do this? 我该怎么做?

I using VS2010 and MySQL - in case I didn't already mention that. 我使用VS2010和MySQL-以防万一我没有提到。 Thanks. 谢谢。

//Kismet //天命

MySQL: MySQL的:

SELECT *
FROM table
WHERE DATE(datecol) BETWEEN DATE(NOW()) AND DATE(DATE_ADD(NOW(), INTERVAL x DAY));

See FIDDLE FIDDLE

this is the query for MySQL and 这是对MySQL的查询,

finds all the records with a date value that's X number of days from today 查找日期为今天的X天数的所有记录

SELECT *
FROM table
WHERE date_column = CURRENT_DATE + INTERVAL X DAY

this one will find all records with a date value between today and X numbers of days from today 该记录将查找日期介于今天和从今天起X天之间的所有记录

SELECT *
FROM table
WHERE date_column BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL X DAY

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

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