Joseph Thomas Mallinson Joseph Thomas Mallinson - 26 days ago 17
PHP Question

php mysqli statement with time

I have the statement below that changes what is displayed depending on what time/day it is.

<?php $new = $mysqli->query("SELECT latedate FROM skiptonevents WHERE status='Active' ORDER BY id DESC LIMIT 1");
while($row = $new->fetch_assoc()) {
$late=$row["latedate"];
if($late < $datetime){
include_once('skiptonone.php');
}
else {
include_once('skiptontwo.php');
}
}
?>


In my database I have a column called latedate (0000-00-00 00:00:00).

$datetime = date('Y/m/d H:i:s');


I am trying to make it show (skiptonone.php) if todays date ($datetime) is less than latedate in the database ($late).

If latedate is after todays date to show skiptontwo.php

Could you please point me in the right direction as my current code does not work properly. It only shows skiptonone.php at the moment regardless of what time is in latedate.

Answer

Change

if($late < $datetime){

for

if(strtotime($late) < time()){

This is because you're doing string comparison otherway.

Comments