Jump to content

Checking if date given in post is older than current date


Recommended Posts

Hey,

I have been coding a bit on a site where you can login, submit your schedule in the form of posts. My problem is, that the users give a date to where the post is going to happen, and i wan't to check if the given date from the post is older than the current date. If so, then hide/do not show the post.

Like this

POST:

Work the 22/02-10 at 19:00 - 20:00            <---- meaning the 22nd of February 2010

CURRENT DATE:

24/02-10

Then it should hide/remove the post so it isn't viewable.

 

My php code is:

<?php
include "../../scripts/config.php";
include "../include/session.php";
global $max_items;

$query = "SELECT calID, calDate, calName, calDesc," . "DATE_FORMAT(calDate, 'd/m-y') as date " . "FROM calTbl WHERE calUser='$username' ORDER BY calDate ASC";
$result = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
$calID = strip_tags( $row['calID']);
$calStamp = $row['calStamp'];
$calDate1 = strtotime( $row['calDate']);
$calDate = strip_tags( $row['calDate']);
$calName = strip_tags( $row['calName']);
$calDesc = nl2br (strip_tags ($row['calDesc'], '<a><b><i><u>'));

echo "<p><b>($calID) $calName the $calDate at $calDesc</b></p>";
echo "<p>----------------------------------------------------------------</p>";}

?>

 

Any help would be appreciated, and if this post needs clarification please say so.

In Advance, thx for any help.

Thanks for your reply. I've been trying to use curdate() but couldn't get that to work...

Anyways, I implemented the function AND calDate>NOW() , but now it only displays the ones 3 days ahead of current time.

Example:

 

Todays date is the 7th

using the NOW() statement, I can only see the ones from the 10th, and not the 9th or 8th.

Now my question, i guess, is, how would one subtract time from the NOW() statement.

so it'll be like "AND calDate>NOW()-(3 days)"?

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.