Comparing timestamp with date variable (MySQL and PHP)

后端 未结 3 724
逝去的感伤
逝去的感伤 2021-01-19 23:01

Any help is highly appreciated.

Say I have a MySQL database with a timestamp column with the value \"1305590400\", how can I compare that with a PHP variable of say

相关标签:
3条回答
  • 2021-01-19 23:02

    You don't get results that probably $date has some time offset and is not equal to 00:00:00 in your timezone.

    WHERE timestamp_column BETWEEN '" . strtotime($date) . "' AND '" . strtotime($date, '+1 day') . "'
    

    or to be more precise:

        WHERE timestamp_column >= '" . strtotime($date) . "'
          AND timestamp_column < '" . strtotime($date, '+1 day') . "'
    
    0 讨论(0)
  • 2021-01-19 23:16

    Simply

    SELECT [...] WHERE '$you_var' = date(`timestamp_column`);
    

    MySQL date() function

    0 讨论(0)
  • 2021-01-19 23:19

    You could always convert the timestamp to a formatted date.

    SELECT FROM_UNIXTIME(1358871753,'%Y %D %M');
    

    Produces: 2013 22nd January

    0 讨论(0)
提交回复
热议问题