I am comparing two datetime in the SQL statement. This is done in PHP.
$result=mysqli_query($con,"SELECT
*
FROM
join
WHERE
join_date <= '$last_join_dates'
ORDER BY
join_date DESC LIMIT 3 OFFSET 3");
$last_join_dates gets update every time, so that I use offset to keep pulling in new data. However, comparing the date is not actually working.
Inside database: structure join_date looks like 2015-10-24 13:30:22 and it is a datetime type.
$last_join_datesI use is the exact same format 2015-10-26 08:23:22.
Since that doesn't work.. I tried the following to convert them.
TRIED FORMAT() the datetime, but does not work:
$result=mysqli_query($con,"SELECT
*
FROM
join
WHERE
FORMAT(join_date, 'yyyyMMddhhmmss') <= FORMAT($last_join_dates, 'yyyyMMddhhmmss')
ORDER BY
join_date DESC LIMIT 3 OFFSET 3");
TRIED Convert() the datetime, but doesn't seem to work either:
$result=mysqli_query($con,"SELECT
*
FROM
join
WHERE
REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(19), CONVERT(DATETIME, join_date, 112), 126), '-', ''), 'T', ''), ':', '') <= REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(19), CONVERT(DATETIME, $last_join_dates, 112), 126), '-', ''), 'T', ''), ':', '')
ORDER BY
join_date DESC LIMIT 3 OFFSET 3");
I'm not sure how to debug this.. Any suggestions?