Jump to content

Comparing dates ..


chelnov63

Recommended Posts

I have a database table called concerts and one of the fields is a date field called concert_date which holds the date in the format: YYYY-MM-DD

 

Now in on one of the php pages i want to show (in three different tables):

 

all concerts which are today..

 

all concerts which are tommorow

 

all concerts which are within a week...

 

i've started off like this:

 

$today = date("Y")."-".date("m")."-".date("d");
$tommorow = ?????;
$within_a_week = ????

//query for concerts today
$result_today = mysql_query("SELECT * FROM concerts WHERE concert_date = '$today'");

 

but how do i get the results for tommorow and for concerts within a week (excluding today and tommorow)

 

thanks in advance for you help :)

 

Link to comment
https://forums.phpfreaks.com/topic/149985-comparing-dates/
Share on other sites

you would try this

<?php
$unix['day'] = strtotime("+1 day"); 
$unix['week'] = strtotime("+1 week"); 
$tomorrow = date("Y-m-d", $unix['day']);
$within_a_week = date("Y-m-d", $unix['week']);

$result_today = mysql_query("SELECT * FROM concerts WHERE concert_date = '$today'");
$result_tomorrow  = mysql_query("SELECT * FROM concerts WHERE concert_date = '$tomorrow");
$result_week = mysql_query("SELECT * FROM concerts WHERE concert_date <= '$today'" OR concert_date >= '$within_a_week');
?>

 

havent tried the sql.. but i know the php returns the right date

Link to comment
https://forums.phpfreaks.com/topic/149985-comparing-dates/#findComment-787700
Share on other sites

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.