Jump to content

Querying a database with Dates in PHP and MySQL with the current date


uniboy86

Recommended Posts

<?php

require "connect.php";

$today = Date('Y-m-d');

$query = "Select * from booking where arrivaldate=".$today;

$result = mysql_query($query, $connection)

or die("Unable to perform query<br>$query");

?>

<html>

<head>

<title>Date</title>

</head>

<body>

<?php  print $today ?>

<?php

while($row=mysql_fetch_array($result))

{ ?>

 

<?=$row['BookingId']?><br>

<?=$row['arrivaldate']?><br>

<?=$row['DepartureDate']?><br>

 

<? } ?>

</body>

</html>

 

I would like to know what the syntax i use to compare the current date to the ArrivalDate in a database table. I have checked the date formats and they are as follows: YYYY-MM-DD

 

Can some please help with how I do the query to check dates against current date

More to the point, what format is arrivaldate?

 

If it's DATE type, you can use

 

$query = "Select * from booking where arrivaldate=CURDATE()";

 

ElseIf it's DATETIME, you can use

 

$query = "Select * from booking where DATE(arrivaldate)=CURDATE()";

 

Else

 

Better tell us.

 

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.