0

I Have following structure in my database :

id    |   date   |   time
(int)  (varchar)   (varchar)

is storing date & time like this :

date          time 
2020-07-04  06:15:00

Now i want to get those record whose current date & time is less than 2 hours, so i'm getting all records using normal select and

$current_time = date("Y-m-d h:i:s"); 
$datetime1 = new DateTime();
$datetime2 = new DateTime($row->date.' '.$row->time);
$interval = $datetime1->diff($datetime2);
$elapsed = $interval->format('%h hours');

but here what i'm getting is, if my database time has passed then also hours contains value, so if i want to get records which have 2 hours left when comparing the current time then after current datetime has passes then also i will get those rows but i don't want those rows whose time has passed.

user3653474
  • 3,393
  • 6
  • 49
  • 135

0 Answers0