Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Help Using Date Range with findAll
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
BlenderStyle  
View profile  
 More options Feb 28 2007, 7:10 pm
From: "BlenderStyle" <BlenderSt...@gmail.com>
Date: Thu, 01 Mar 2007 00:10:13 -0000
Local: Wed, Feb 28 2007 7:10 pm
Subject: Help Using Date Range with findAll
I'm trying to find all Posts within a given range of dates (the month
of February 2007 in this example), and I can't figure it out.

This isn't returning any results:
$conditions['Post.created'] = array('>= 2007-02-01', '<= 2007-02-28');
$this->Post->findAll($conditions);

The strange part is that this works:
$conditions['Post.created'] = '>= 2007-02-01';
$this->Post->findAll($conditions);

And so does this:
$conditions['Post.created'] = '<= 2007-02-31';
$this->Post->findAll($conditions);

And so does this, assuming that posts exist on both those days, and it
only returns posts on those days:
$conditions['Post.created'] = array('2007-02-01', 2007-02-31');
$this->Post->findAll($conditions);

It also works if I query the database directly like this:
select * from posts where created >= '2007-02-01' && created <=
'2007-02-31';

Am I missing somthing? Why isn't this working?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlenderStyle  
View profile  
 More options Feb 28 2007, 7:13 pm
From: "BlenderStyle" <BlenderSt...@gmail.com>
Date: Thu, 01 Mar 2007 00:13:31 -0000
Local: Wed, Feb 28 2007 7:13 pm
Subject: Re: Help Using Date Range with findAll
It's worth noting that this isn't working either:
$conditions['Post.id'] = array('>= 1', '<= 10');
$this->Post->findAll($conditions);

I think I don't understand how Cake deals with these ranges.

On Feb 28, 4:10 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlenderStyle  
View profile  
 More options Feb 28 2007, 10:19 pm
From: "BlenderStyle" <BlenderSt...@gmail.com>
Date: Thu, 01 Mar 2007 03:19:50 -0000
Local: Wed, Feb 28 2007 10:19 pm
Subject: Re: Help Using Date Range with findAll
I figured it out. I did this:
$conditions[]['Post.created'] = '>= 2007-02-01';
$conditions[]['Post.created'] = '<= 2007-02-28';
$this->Post->find($conditions);

It seems the complex conditions section in the model chapter in the
CakePHP Manual was wrong. It seems as Cake continues, the manual just
seems older and older. Oh well, Cake still rocks.

On Feb 28, 4:13 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlenderStyle  
View profile  
 More options Feb 28 2007, 10:18 pm
From: "BlenderStyle" <BlenderSt...@gmail.com>
Date: Thu, 01 Mar 2007 03:18:07 -0000
Local: Wed, Feb 28 2007 10:18 pm
Subject: Re: Help Using Date Range with findAll
I figured it out. I did this:
$conditions[]['Post.created'] = '>= 2007-02-01';
$conditions[]['Post.created'] = '<= 2007-02-28';
$this->Post->find($conditions);

It seems the complex conditions section in the model chapter in the
CakePHP Manual was wrong. It seems as Cake continues, the manual just
seems older and older. Oh well, Cake still rocks.

On Feb 28, 4:13 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlenderStyle  
View profile  
 More options Feb 28 2007, 10:18 pm
From: "BlenderStyle" <BlenderSt...@gmail.com>
Date: Thu, 01 Mar 2007 03:18:07 -0000
Local: Wed, Feb 28 2007 10:18 pm
Subject: Re: Help Using Date Range with findAll
I figured it out. I did this:
$conditions[]['Post.created'] = '>= 2007-02-01';
$conditions[]['Post.created'] = '<= 2007-02-28';
$this->Post->find($conditions);

It seems the complex conditions section in the model chapter in the
CakePHP Manual was wrong. It seems as Cake continues, the manual just
seems older and older. Oh well, Cake still rocks.

On Feb 28, 4:13 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
AD7six  
View profile  
 More options Mar 1 2007, 4:03 am
From: "AD7six" <andydawso...@gmail.com>
Date: Thu, 01 Mar 2007 01:03:30 -0800
Local: Thurs, Mar 1 2007 4:03 am
Subject: Re: Help Using Date Range with findAll

On Mar 1, 4:18 am, "BlenderStyle" <BlenderSt...@gmail.com> wrote:

> I figured it out. I did this:
> $conditions[]['Post.created'] = '>= 2007-02-01';
> $conditions[]['Post.created'] = '<= 2007-02-28';
> $this->Post->find($conditions);

> It seems the complex conditions section in the model chapter in the
> CakePHP Manual was wrong. It seems as Cake continues, the manual just
> seems older and older. Oh well, Cake still rocks.

There is no error in the manual wrt to how to generate array
constraints; I think there is a simple misunderstanding.

$conditions['Post.created'] = array('>= 2007-02-01', '<=
2007-02-28');
will generate
... WHERE `Post`.`created` IN ('>= 2007-02-01', '<= 2007-02-28') ...
which is obviously not what you wanted. using an array in that manner
ONLY generates an IN statemnet, it isn't used to build a list of
conditions to apply to the same field, where in the manual does it
suggest this will work?

There are several alternatives to the final solution you found (just
for info)
1)
$conditions['Post.created'] = '>= 2007-02-01';
$conditions[]['Post.created'] = '<= 2007-02-28';
The only reason the extra array (or arrays in your solution) are
needed is because otherwise you would overwrite one condition with
another.

2)
$conditions['Post.created'] = 'BETWEEN 2007-02-01 AND 2007-02-28';
(iirc)

>Oh well, Cake still rocks.

indeederoony :)

Cheers,

AD


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlenderStyle  
View profile  
 More options Mar 1 2007, 11:49 am
From: "BlenderStyle" <BlenderSt...@gmail.com>
Date: Thu, 01 Mar 2007 16:49:37 -0000
Local: Thurs, Mar 1 2007 11:49 am
Subject: Re: Help Using Date Range with findAll
Thanks, AD! That cleared up a lot for me. You're posts are always so
informative. I'm going to star this for later.

On Mar 1, 1:03 am, "AD7six" <andydawso...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan  
View profile  
 More options Mar 27 2007, 1:25 pm
From: "Dan" <dan.bri...@gmail.com>
Date: Tue, 27 Mar 2007 17:25:09 -0000
Local: Tues, Mar 27 2007 1:25 pm
Subject: Re: Help Using Date Range with findAll
Hi,

bit of a noob so this could well be my problem (isn't it always ;)

I'm doing a little date comparison  such as you suggested

> 2)
> $conditions['Post.created'] = 'BETWEEN 2007-02-01 AND 2007-02-28';
> (iirc)

 but not getting any results. So I dumped out the contents of the cake
generated SQL and it's escaping the 'BETWEEN' as:

"(`Post`.`created` = ' BETWEEN 2007-2-01' AND ' 2007-03-01')

Am I doing anything wrong? it looks like the SQL generator in cake is
not "seeing" BETWEEN as a reserved word?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »