Jump to content

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

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.