duanbu1998 2017-01-04 15:39 采纳率: 0%
浏览 18

来自mysql数据库的过去和现在事件今天通过使用php进行比较

i want to get past and future events from database and by using php-mysql query, and i had try with this query

select * from table name where date >date();

but i got the past events in future section. and i saved date in varchar data type. please help me Thank You

  • 写回答

1条回答 默认 最新

  • dongwei2030 2017-01-04 15:44
    关注

    Use NOW() MySQL function to get current timestamp and STR_TO_DATE function to convert string date to date format

    select * from table_name where STR_TO_DATE(date, '%Y-%m-%d %H:%i:%s') > now();
    

    But you really should consider to alter your table to TIMESTAMP data type

    评论

报告相同问题?