Jump to content

MySQL - CompareDates?


mikey3521

Recommended Posts

Hello, I'm working on a community site and have a question on how to-do the following.

 

I want to grab a date from the database, then see if its 5 days or less away... so what i want todo is...

 

select `date` from `users` where `username` = 'mike'

if (`date` is... 5days or less away from today... then) {

echo "Event Is Soon";

} else {

}

 

thoughts? Im not quite sure how to compre the date to todays date, and then calculate if its 5 days or less away... I should also mention the date field in the database returns this : 6/19/1984

Link to comment
https://forums.phpfreaks.com/topic/56469-mysql-comparedates/
Share on other sites

Something similar to this (this is shortened):

 

<?php
$myDate = '6/19/1984';   // From DB
list($cmonth,$cday,$cyear) = date("j/m/Y");  // Current Date
list($month,$day,$year) = explode("/",$myDate);
$diff = $cday - $day;
if($diff < 6){
   echo 'Less than 5 days left!';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/56469-mysql-comparedates/#findComment-278893
Share on other sites

How would I do this but only in one direction, as in.. if the date hasn't come yet & its within 5 days.. that way im not getting bad info. Cause if the date was yesterday its past.. but its still smaller then 5.. but i don't want it to show past dates.. only today and upcomming

Link to comment
https://forums.phpfreaks.com/topic/56469-mysql-comparedates/#findComment-278996
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.