简体   繁体   English

从今天起检索加入日期少于 15 天的行

[英]Retrieve rows with joining date less than 15 days from today

Mysql query is Mysql查询是

SELECT 
    userid as uid, 
    CONCAT( firstname, ' ', lastname ) AS name,
    profileimage,
    joining_date, 
    role as designation
FROM pr_users_details
INNER JOIN pr_users ON pr_users.id = pr_users_details.userid
LEFT JOIN pr_userroles ON pr_userroles.id = pr_users.userroleid
WHERE joining_date > DATE_SUB( NOW()-1 , INTERVAL 15 DAY )
ORDER BY pr_users_details.id DESC

I am getting these results which are a year old.我得到了这些一年前的结果。 I want to display new hires , ie todays date - 15 days.我想显示新员工,即今天的日期 - 15 天。 Am i missing something.我是不是错过了什么。

在此处输入图片说明

You should store date/times as date times, not strings.您应该将日期/时间存储为日期时间,而不是字符串。 For the comparison to work, you need to convert the value to a string:为了进行比较,您需要将值转换为字符串:

WHERE STR_TO_DATE(joining_date, '%d-%m-%Y') > DATE_SUB( NOW()-1 , INTERVAL 15 DAY )

However, you should fix the data:但是,您应该修复数据:

update ?  -- whatever the table is
    set joining_date = STR_TO_DATE(joining_date, '%d-%m-%Y');  -- this will convert the date to a canonical format

alter table t alter column joining_date date;

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

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