MYSQL选择日期早于datetime的行

时间:2022-02-09 11:20:47

I am coding a status item for a website and need to load statuses older than a variable that contains a datetime.

我正在编写网站的状态项,并且需要加载比包含日期时间的变量更早的状态。

So the database has a field called added date which is a datetime field and I have a string in datetime format and i want to select all rows older than my datetime format string.

所以数据库有一个名为添加日期的字段,这是一个日期时间字段,我有一个日期时间格式的字符串,我想选择比我的日期时间格式字符串更早的所有行。

How would this be structured in MYSQL?

如何在MYSQL中构建它?

Thanks in advance.

提前致谢。

3 个解决方案

#1


22  

 select status_column from your_table
 where added_date < '2012-05-12'

#2


5  

mysql DATETIME type is used for values that contain both date and time parts.

mysql DATETIME类型用于包含日期和时间部分的值。

Try this

尝试这个

SELECT datecolumn 
FROM table
WHERE datetime_date > '2012-05-12 01-32-56'

#3


1  

try this

尝试这个

$today = date('Y-m-d');

 SELECT column_name FROM table_name WHERE year(added_date) > $today AND month(added_date) > $today

#1


22  

 select status_column from your_table
 where added_date < '2012-05-12'

#2


5  

mysql DATETIME type is used for values that contain both date and time parts.

mysql DATETIME类型用于包含日期和时间部分的值。

Try this

尝试这个

SELECT datecolumn 
FROM table
WHERE datetime_date > '2012-05-12 01-32-56'

#3


1  

try this

尝试这个

$today = date('Y-m-d');

 SELECT column_name FROM table_name WHERE year(added_date) > $today AND month(added_date) > $today