Where date = today?

1

I'm trying to pull items from a pod where entry_date = todays date.

I have it working with hard coded values, but I want to pull it dynamically. When I use the code below, I seem to get a mysql error around where 00:00:00 starts. (I do the zeros because thats how pods outputs the date)

Am I missing something or is this just sloppy php on my end?

            <?php    
                    $today = ""(date('Y-d-m')" 00:00:00");
                    $competition = new Pod('competition'); 
                    $competition->findRecords('entry_date ASC',10,"entry_date = ".$today.""); 
                    $total_competitions = $competition->getTotalRows();   ?>
                <?php if( $total_competitions>0 ) : ?>
                  <?php while ( $competition->fetchRecord() ) : ?>
                    <?php
                      // set our variables
                      $competition_name        = $competition->get_field('name');
                      $competition_link        = $competition->get_field('slug');
                      $competition_lat      = $competition->get_field('lat');
                      $competition_long         = $competition->get_field('long'); 
                      $competition_date         = $competition->get_field('entry_date');  
                    ?>
                        <li><?php echo $competition_name; ?>-<?php echo $today; ?> - <?php echo $competition_date; ?></li>                          
                  <?php endwhile ?>
               <?php else : ?> <li>No Competitions today <?php echo $today; ?>, see whats <a href="/dev/calendar">coming up?</a></li>
            <?php endif ?>

asked Jul 6 '10 at 5:32

wesbos

56

add comment
enter at least 15 characters

1 Answer

1

Your PHP skills are fine, the problem is in your MySQL WHERE clause syntax.

With what you have written, you'll only get items that were entered today at Midnight.

Try replacing the first four lines of your code with this:

<?php    
        $competition = new Pod('competition'); 
        $competition->findRecords('entry_date ASC',10,'DATE(t.entry_date) = CURDATE()'); 

See the MySQL manual on Date Functions for more information.

answered Jul 7 '10 at 1:02

chris.pilko

889

add comment
enter at least 15 characters