Jump to content

Checking between a range of 2 dates


jacko_162

Recommended Posts

i have the below code which i wrote this monring, for some reason when i assign $date to fetch data from my database i just get the echo of "You had an Error" yet if i manually assign $date as the following it works:

 

$date = strtotime("2011-09-20");

 

i have it set exactly the same in the database cus if i echo $date

 

i get:

2011-09-20

 

whats going on? date in php is a cruel function to play around with..

 

here is my code:

<?php
// Query the DB to fetch all data where member_id matches that set in session
$reminder = mysql_query("SELECT * FROM `reminders` WHERE member_id=$_SESSION[sESS_MEMBER_ID]") or die(mysql_error());
//While Loop the results
while($fetch = mysql_fetch_array( $reminder )) { 
// Start date (TODAY!)
$s_date = strtotime("now"); 
// End Date (+7 days from today)
$e_date = strtotime("+1 week"); 
// Fetches Date stamp from "reminderDate" row in DB
$date = $fetch['reminderDate']; 

// Checks if the date is between 2 ranges set above
if($date > $s_date && $date < $e_date) 

//Echo The Results
{
    echo "<div class='notification error png_bg'><a href='#' class='close'><img src='img/cross_grey_small.png' title='Close this notification' alt='close' /></a><div>Custom Error Notification BOX!</div></div>";
}
else
{
    echo "You had an Error";
//echo $date; // TEST that date outputs datestamp "2011-09-02"
}
//END LOOP
}
?>

Link to comment
Share on other sites

Since you have a DATE data type, why don't you just write a query to match the rows that you want? Mysql has a couple dozen date functions that make using dates easy.

as PFM suggested, perhaps a mysql solution here would be much easier..

refer here for a reference of mysql's date/time functions

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.