Solved

Don't display dates before today...

Posted on 2013-01-21
3
227 Views
Last Modified: 2013-01-21
I have built a site with an events diary.

On the home page I display the next 4 events by selecting 4 recording from start_date ASC.

live
SELECT id, start_date, end_date, date_format(`start_date`,'%D %M %Y') as `formattedDate`, end_time, title, `description`, venue, link, icon, image, image_alignment, status FROM eventer_events ORDER BY start_date ASC

Open in new window


<span class="purpletext"><?php echo $row_latestnews['title']; ?></span><br>
          </h3>
          <span class="venuefeed"><?php echo $row_latestnews['venue']; ?></span><br>
          <?php echo $row_latestnews['formattedDate']; ?> </div>
      </div>
      <?php } while ($row_latestnews = mysql_fetch_assoc($latestnews)); ?>

Open in new window


The problem is that dates that have past will show at the top of the list. I need to not display an event that has already past, any ideas how to do this?

The date value is in the database as varchar(10) by the way...
0
Comment
Question by:BrighteyesDesign
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
ingwa earned 500 total points
ID: 38801745
May I recommend you look at an article I wrote about dates:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_3935-Working-with-Dates-and-Time-using-PHP-and-MySQL.html

Reason being is that there are some very powerful features available to you simply by setting your date field to a timestamp. It only takes up 4 bytes too.

The answer to your question is:

SELECT id, start_date, end_date, date_format(`start_date`,'%D %M %Y') as `formattedDate`, end_time, title, `description`, venue, link, icon, image, image_alignment, status FROM eventer_events where start_date > now() and end_date > now() ORDER BY start_date ASC

Open in new window


I put the clause on both the start and end dates just in case there was something funky going on with the end dates. If now() doesn't give you the value you need since you aren't using a timestamp you may have to preformat a variable with a date to filter by before constructing the sql. I do recommend against this though.
0
 

Author Comment

by:BrighteyesDesign
ID: 38801813
Great link, thanks, i'll use that next time.

I'm going to use the lazy option for now though!
0
 
LVL 18

Expert Comment

by:ingwa
ID: 38801820
Glad I was able to assist. Good luck with your project.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 5 123
Jquery Autocomplete PHP script 3 23
Not needed 13 58
mysql left join sentence 7 22
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now