ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Querying daterange with Query Module

March 31, 2011 8:00am

Subscribe [3]
  • #1 / Mar 31, 2011 8:00am

    jamestowers

    53 posts

    How can I query a date range using the values in the entry_date column of exp_channel_titles?
    I’m using POST variables output as 2011-03-31 to get the ranges which is why I can’t work it out, I need to convert those dates to something like 1295534112

    {exp:query sql="SELECT * FROM exp_channel_data LEFT JOIN exp_channel_titles ON exp_channel_data.entry_id=exp_channel_titles.entry_id WHERE exp_channel_data.channel_id ='7' AND exp_channel_titles.author_id = '{embed:author}' ORDER BY entry_date DESC "}
                <tr>
                    <?php if ($col1){ echo '<td>{title}</td>'; } ?>
                    <?php if ($col2){ echo '<td>{year}/{month}/{day}</td>';} ?>
                    <?php if ($col3){ echo '<td>{field_id_85}</td>'; } ?>
                    <?php if ($col4){ echo '<td>{field_id_95}</td>'; } ?>
                    <?php if ($col5){ echo '<td></td>'; } ?>
                    <?php if ($col6){ echo '<td>£{field_id_51}</td>'; } ?><?php $total += {field_id_51};?>
                    <?php if ($col7){ echo '<td>£{exp:simple_math calculate="{field_id_51} * 0.2"}</td>'; } ?><?php $ncc += {exp:simple_math calculate="{field_id_51} * 0.2"};?>
                    <?php if ($col8){ echo '<td>£{exp:simple_math calculate="{field_id_51} * 0.8"}</td>'; } ?><?php $net += {exp:simple_math calculate="{field_id_51} * 0.8"};?>
                    <?php if ($col9){ echo '<td>£{exp:simple_math calculate="{field_id_51} * 0.2"}</td>'; } ?><?php $ncc += {exp:simple_math calculate="{field_id_51} * 0.2"};?>
                </tr>
            {/exp:query}


    Thanks in advance!
    James

  • #2 / Mar 31, 2011 4:03pm

    Kay Ashaolu

    23 posts

    I’m thinking you could convert a string like 2011-03-31 to a unix timestamp using the DateTiem class. Maybe something like this:

    <?php 
          $date = new DateTime($_POST['date']);
          $dateTimeStamp = $date->getTimestamp();
    ?>

    You can check out the php Date/Time links at http://www.php.net/manual/en/class.datetime.php

  • #3 / Mar 31, 2011 5:40pm

    Sue Crocker

    26054 posts

    Thanks for the assist, Kay.

    James? Something to think about.

  • #4 / Apr 01, 2011 5:19am

    jamestowers

    53 posts

    Thanks Kay, that’s exactly what i was looking for!

  • #5 / Apr 01, 2011 6:57am

    Sue Crocker

    26054 posts

    Glad was was able to help!

    James - Feel free to start a new thread if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases