-1

Please help on how to compare a date with date in database in php

something like

$today = date("y-m-d");
select * from table name where date <= $today

It is not working this way

Please help

Aurasphere
  • 3,841
  • 12
  • 44
  • 71
Ademaintain
  • 137
  • 2
  • 13

2 Answers2

1

Try this

SELECT * FROM table_name WHERE date <= CURDATE() 

You can also use

SELECT NOW(),CURDATE(),CURTIME()

will result in something like this:

NOW() --> 2014-11-22 12:45:34
CURDATE() --> 2014-11-22
CURTIME() --> 12:45:34

For more information go to this link

Med Dhiia
  • 64
  • 4
  • Thanks, i already have date in the database, i want where date is less than or equal to current date in the database, what i simple want to code is an expiry date. – Ademaintain Apr 28 '17 at 14:04
0

Add quotes:

$sql = "select * from table name where date <= '{$today}';

And field date in database set as datetime

Kilian Stinson
  • 2,376
  • 28
  • 33