sabbagh
sabbagh

Reputation: 21

How to compare date with date that stored in database in php

How can I compare date with date that was stored in database. for example I have 2 dates(date1 and date2) in format date and I want to get dates that are between these dates(date1< I need these dates

How can I compare these dates in select query?

I use this query but it doesn't work:

   $sql="select name from person where date <'$from_date'";
   $result=mysqli_query($con,$sql);
   if(!mysqli_query($con,$sql))
   {
    die('error' .mysqli_error($con));
   } 

Upvotes: 0

Views: 461

Answers (2)

Curt
Curt

Reputation: 5722

For compatibility, format your dates in ISO mode ("YYYY-MM-DD HH:mm:ss.xxx"). You can leave off the whole time portion, or just the milliseconds, or the seconds and milliseconds. When passed as literals in an SQL query, they should be single-quoted strings.

Today is: '2013-07-12' Right now is: '2013-07-12 13:38:03'

Upvotes: 0

Chris78
Chris78

Reputation: 387

Simply use the BETWEEN statement.

WHERE date BETWEEN 'Older Date Here' AND 'Newer Date Here'

Upvotes: 1

Related Questions