0

iam saving a date to my database as timestamp ( int field )

Now i have an external date in my php which i convert also into timestamp to compare it later. I must make the check in the query, i cant select the date from the db before to compare them afterwards

What i need: I wanna see if the external date is same date as the stored int value. the compare should only cover yyyy-mm-dd

little example.

my external date is 2011-02-23, which is only present without hours, the stored timestamp is lets say 123747382

What would a mysql query where clause look like, or what php am i missing in order to know that both stamps are the same date?

$r_date = '2011-02-23';
$stamp_day = strtotime($r_date);

WHERE addtime = '{$stamp_day}'

addtime would be the stored timestamp in the int field

Thank you

0

1 Answer 1

2

try this:

"WHERE DATE( FROM_UNIXTIME( `addtime` ) ) = '$r_date'"

or:

"WHERE DATE( FROM_UNIXTIME( `addtime` ) ) = DATE( FROM_UNIXTIME( '$stamp_day' ) )"
1
  • FROM_UNIXTIME('$stamp_day', '%Y-%D-%M') might also work without DATE(), not sure. Havent tested it
    – Fritz
    Dec 23, 2011 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.