Selecting data in a specific date range
Sometimes, you have to return all objects created in a specific date range, e.g. you want to return all posts created in the last thirty days. Thanks to the nice functions for date operations provided by MySQL this task is simple:
$this->Post->findAll(
'WHERE Post.created >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)');




Thanks for the tip.
Just one suggestion - the code in all your posts is always cut off. Not a big thing but it would be great to find a solution to it.
Thanks,
Mandy.
Please put your code in scroll-div.
Good tip. Like Mandy said, though, the code being cut off can be a bit annoying. I do realize I can copy/paste it just fine, though.
I think adding an overflow: auto to your #content pre element would cause it to scroll. Might want to also put a height on it so the code blocks are all a fixed height.
Just some thoughts, thanks for your blog. I’m learning cake and liking it quite a bit so far.
I just added a plugin that uses geshi to render inline source
SyntHythol http://indyjt.com/software/ you might check it out, you just wrap the code in pre tags with a lang attribute of the language. See an example at http://blog.samdevore.com/cakephp-pages/old-fart-in-the-oven/ (you have to check the box, but I bet you have read the manual) ;)
Sam D
Is it right to put the “WHERE” in the argument?
@Mandy, majna, gRegor: Thanks for your feedback. I will switch to another theme today which should fix the issues with posted code snippets.
@Sam D: The plug-in looks promising, but unfortunately I cannot install plug-ins here on wordpress :|
@ricardo couto: The “WHERE” is not necessary, you can omit it, and it still works.
[...] Selecting data in a specific date range « cakebaker Adding a where clause to $this->Post->findAll() (tags: cakephp sql) [...]