Group by Date - Datetime Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kenny Ken
    New Member
    • Feb 2011
    • 2

    Group by Date - Datetime Problem

    Guys, I really need your help on this one.

    I have a list of articles using smarty I want to organize by date,

    Date1
    ArticleA
    Date2
    ArticleB
    ArticleC

    The problem I am having is that on Date2 (or if there are more than 1 articles posted on the same day) the entire Date2 shows up again...i.e

    Date1
    ArticleA
    Date2
    ArticleB
    ArticleC
    Date2
    ArticleB
    ArticleC

    What I THINK the problem is, is that the Date2 is a datetime for when the article was posted, so the reason its repeating each time is because the time values are different.

    I need to find a way to remove the time value from datetime or somehow manipulate it to show just the date.

    Here is my code
    sql
    Code:
    $sql = 'select ' . TABLE_ADS . ('' . '.*' . $mlang_vars . ', ') . TABLE_ADS . '.id as adid, ' . TABLE_ADS_PICTURES . '.picture, ' . TABLE_ADS_PICTURES . '.`id` as `picture_id`, date_format(' . TABLE_ADS . ('' . '.`date_added`,\'' . $date_format . '\') as date_nice, date_format(') . TABLE_ADS . ('' . '.`date_expires`,\'' . $date_format . '\') as date_expires_nice, (') . TABLE_ADS . ('' . '.date_expires < \'' . $timestamp . '\' and ') . TABLE_ADS . '.date_expires!=\'0000-00-00 00:00:00\' and ' . TABLE_ADS . '.active=0) as expired, ' . TABLE_CATEGORIES . '_lang.name as category, ' . TABLE_PACKAGES . '.amount as amount, ' . TABLE_USERS . ('' . '.username as username ' . $pri_name . ' ' . $video . ' ' . $q_vars . ' from ') . TABLE_ADS . '
    		LEFT JOIN ' . TABLE_CATEGORIES . '_lang on (' . TABLE_ADS . '.category_id=' . TABLE_CATEGORIES . '_lang.id and ' . TABLE_CATEGORIES . ('' . '_lang.`lang_id` = \'' . $crt_lang . '\') 
    		LEFT JOIN ') . TABLE_PACKAGES . ' on ' . TABLE_ADS . '.package_id=' . TABLE_PACKAGES . '.id 
    		LEFT JOIN ' . TABLE_USERS . ' on ' . TABLE_ADS . '.user_id=' . TABLE_USERS . '.id 
    		LEFT JOIN ' . TABLE_ADS_PICTURES . ' on ' . TABLE_ADS . '.id=' . TABLE_ADS_PICTURES . ('' . '.ad_id
    		' . $pri_join . '
    		' . $video_join . '
    		' . $q_join . '
    		') . $where . ' group by ' . TABLE_ADS . '.id ' . $order_by . ' ' . $order_way . ' ';
    php
    Code:
    {foreach from=$listings_array name="date_nice" item=k}{$k.date_nice}
        {foreach from=$listings_array  name="listing" item=v}
           {if $k.date_nice==$v.date_nice}
                {include file="short_listing.html"}
           {/if}
        {/foreach}
    {/foreach}
    Any help will be appreciated. Thanks
  • RuthC
    New Member
    • Nov 2007
    • 33

    #2
    Use date_format( `date_added` , '%Y-%m-%d' ) like this. you will get only date

    Comment

    • Kenny Ken
      New Member
      • Feb 2011
      • 2

      #3
      thanks. I tried that and I'm still getting the same results, articles posted on the same day duplicating days. i.e

      Date2
      ArticleB
      ArticleC
      Date2
      ArticleB
      ArticleC

      Maybe the php is wrong?

      Comment

      Working...