Current location: Hot Scripts Forums » Programming Languages » PHP » show dates in the future


show dates in the future

Reply
  #1 (permalink)  
Old 06-01-05, 03:54 PM
dripdrown dripdrown is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
show dates in the future

hello everyone and anyone. i've been teaching myself some php/mysql the past few weeks and have made good progress in my opinion. i'm failing with what i would consider to be a simple task. i have records in my database that contain dates. i want to be able to display all dates from the current date and into the future. that way when events that are dated pass by, they will be removed from the listing. conversely, i'm working on a page that does the opposite. display all dates from the current date into the past so people can view events that have already happened. i'm not even sure where to start with this. if you anyone is willing to lend a helping hand it'd be very much appreciated! Thanks.

Anthony
Reply With Quote
  #2 (permalink)  
Old 06-01-05, 05:13 PM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

That depends on the format you store dates in. Maybe I'm mistaken, but I would advocate using Unix timestamp. So doing you will be able to select future or past events with a very simple query like

$sql = "SELECT * FROM events WHERE date > " . time();

or

$sql = "SELECT * FROM events WHERE date < " . time();

You can do some manipulations with the mktime() function to get the 00:00 of any day, or the 1st day of any month and so on. If you however opt to store dates in the MySQL date/time format, refer to the MySQL docs on the date and time handling.
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #3 (permalink)  
Old 06-01-05, 05:41 PM
dripdrown dripdrown is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
currently i've got the following

$query="SELECT * FROM tblSHOWS ORDER BY date ASC";

i edited it to say

$query="SELECT * FROM tblSHOWS ORDER BY date ASC WHERE date >" .time();

getting some sort of error now. forgive my ignorance, i'm probably screwing something up, but this is my first database driven website so i'm still very much a novice.

Anthony
Reply With Quote
  #4 (permalink)  
Old 06-01-05, 05:47 PM
Jaffizzle Jaffizzle is offline
Newbie Coder
 
Join Date: May 2005
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
$query="SELECT * FROM tblSHOWS WHERE date >" .time()." ORDER BY date ASC";

try that
Reply With Quote
  #5 (permalink)  
Old 06-01-05, 06:01 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Greater than or equal to..
>=
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #6 (permalink)  
Old 06-01-05, 10:28 PM
dripdrown dripdrown is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
i think i missed something completely. The date/time is stored in each record. and my code looks like this.

<?php
include("db_info.php");
mysql_connect("mysql.thisismyserver.net",$username ,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tblSHOWS WHERE date >" .time()." ORDER BY date ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close(); ?>

<table border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#CCCCCC" align="left">
<th width="85" height="20"><font face="verdana" size="2">&nbsp; Date</font></th>
<th width="120" height="20"><font face="verdana" size="2">Location</font></th>
<th width="125" height="20"><font face="verdana" size="2">Venue</font></th>
<th width="270" height="20"><font face="verdana" size="2">Bands</font></th>
</tr>

<?php $i=0;
while ($i < $num) {
$date=mysql_result($result,$i,"date");
$location=mysql_result($result,$i,"location");
$venue=mysql_result($result,$i,"venue");
$desc=mysql_result($result,$i,"desc");
?>

<tr align="left">
<td width="85" height="20"><font face="verdana" size="1" color="#cccccc">&nbsp; <? echo $date; ?></font></td>
<td width="120" height="20"><font face="verdana" size="1" color="#cccccc"><? echo $location; ?></font></td>
<td width="125" height="20"><font face="verdana" size="1" color="#cccccc"><? echo $venue; ?></font></td>
<td width="270" height="20"><font face="verdana" size="1" color="#cccccc"><? echo $desc; ?></font></td>
</tr>

<?php
$i++;
}

echo "</table>";
?>

it's still showing all dates... any suggestions?

Anthony
Reply With Quote
  #7 (permalink)  
Old 06-02-05, 01:35 AM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

How do you insert shows into the table? Possibly you calculate wrong dates so that all of them appear to be in far future?
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #8 (permalink)  
Old 06-02-05, 01:52 AM
dripdrown dripdrown is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
i got it

well, after a quick trip to the library and some heavy reading i got it. i'm not exactly sure how or that i understand how it works... but here goes.

i changed just the one line of code...

$query="SELECT * FROM tblSHOWS WHERE TO_DAYS( date ) - TO_DAYS( NOW( ) ) >= 0 ORDER BY date ASC";

there you have it... i solved my own problem... thanks to everyone for your advice / help

Anthony
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using dates and dropdown menus dihan PHP 0 04-22-05 06:12 AM
list all dates - date range lool49 PHP 3 11-12-04 07:53 AM
display all dates between two date dhzen JavaScript 0 07-21-04 11:53 PM
PEAR array days between two dates Dr-Leech PHP 2 03-16-04 10:41 AM
registration of prodid,name,and 2 dates pr. month ropey PHP 3 01-31-04 01:12 PM


All times are GMT -5. The time now is 06:49 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.