如何隐藏已通过日期的数据

时间:2014-04-11 05:47:10

标签: php mysql date

我想要隐藏已经通过的日期。

"SELECT * FROM " . USER_TABLE_NAME . " AS cu 
 INNER JOIN " . JOB_TABLE_NAME . " AS jb 
 ON jb.user_id = cu.user_id 
 WHERE cu.user_id = '$userID' 
 ORDER BY jb.job_date DESC, jb.job_tea_time DESC";

Rightnow我正在获取所有数据order by date.

日期存储在VARCHAR中,我不想改变它。

谢谢,

3 个答案:

答案 0 :(得分:0)

您可以使用strtodate函数将字符串转换为日期 - 之后您可以通过日期函数轻松比较它。

答案 1 :(得分:0)

您可以使用mysql函数unix_timestamp将日期字符串(varchar)转换为unix时间戳,并且为了比较今天的日期,您可以在php中使用strtotime('今天')

"SELECT * FROM " . USER_TABLE_NAME . " AS cu INNER JOIN " . JOB_TABLE_NAME . " AS jb 
    ON jb.user_id = cu.user_id 
WHERE cu.user_id = '$userID' AND unix_timestamp(jb.jobdate) > " . strtotime('today') . "
    ORDER BY jb.job_date DESC, jb.job_tea_time DESC";

这应该有效。如果发现任何问题,请告诉我们!

答案 2 :(得分:0)

我认为这会有所帮助

"SELECT * FROM " . USER_TABLE_NAME . " AS cu 
 INNER JOIN " . JOB_TABLE_NAME . " AS jb 
 ON jb.user_id = cu.user_id 
 WHERE cu.user_id = '$userID' AND STR_TO_DATE(jb.job_date,'%d/%m/%Y') >= now()
 ORDER BY jb.job_date DESC, jb.job_tea_time DESC;