Thanks for the help.  I ended up running this in my user model.  It
seems to work pretty well.

function activePosts ()
        {
          $posts = $this->find('all', array('conditions' => array(
          array('DATE_ADD(Post.created, INTERVAL 30 DAY) >
CURRENT_DATE'))));
          return $posts;
        }

Thanks again!

Lance

On Sep 12, 6:17 pm, cricket <zijn.digi...@gmail.com> wrote:
> On Sun, Sep 12, 2010 at 3:12 PM, Lance <lance3...@gmail.com> wrote:
> > I'm trying to create a expiration field for blog posts that will
> > display something like 25 days to expiration.  I added an expiration
> > DATETIME field in my database.  I want to make it 30 days from the
> > created DATETIME field in my database.  Can anyone steer me in the
> > right direction.  I imagine I'll need to do a find with conditions
> > that will add 30 days to the expiration.  Any advice would be very
> > very helpful.  Thanks in advance.
>
> No need for the extra column as you can just compare the created value
> with the current date to get how many days are left.
>
> $seconds_in_day = 60 * 60 * 24 ;
> $limit = $seconds_in_day * 30; // 30 days
>
> $remaining = mktime() - strtotime($data['Post']['created']);
>
> $days_left = ($limit - $remaining) / $seconds_in_day;
>
> Obviously, you'd need to do something about the float that results. I
> guess rounding up would be the way to go.
>
> You could put this in a model method, eg:
>
> public $expiration_term = 30;
>
> public function getDaysLeft($created)
> {
>         $seconds_in_day = 60 * 60 * 24 ;
>         $remaining = mktime() - strtotime($created);
>
>         return = (int) ceil( ( ( $this->expiration_term * $seconds_in_day ) -
> $remaining ) / $seconds_in_day);
>
> }
>
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to