Select rows from MySQL table where PHP timestamp is older than X

前端 未结 4 543
逝去的感伤
逝去的感伤 2020-12-17 02:12

I have a user table, where users need to be approved, i want to show users who are not approved and is registered more than 7 days ago.

My user_regdate is a timestam

4条回答
  •  青春惊慌失措
    2020-12-17 02:27

    php's time() function outputs a unix timestamp (the number of seconds since January 1 1970). MySQL's now() function outputs a formatted date (like 2011-6-9 12:45:34)... so I don't think you can compare them like that.

    Try using the unix timestamp, minus 7 days, instead of now() in your query:

     $7_days_ago = time() - (7 * 24 * 60 * 60);
     mysql_query("select * from users WHERE user_regdate <" . $7_days_ago . " AND approved='0' order by id;");
    

提交回复
热议问题