Category: Models & ORM

Q: Cakephp find data that was created one month ago

I am working on an API service for creating financial reports. Now I want to limit the application: 

  1. Not to create a new report if there was already an existing report that created in the past one month (like today - created_date < 30 days)
  2. I want a Cakephp find statement that can find an existing or no report.

Can someone help?

1 Answers

Version: 3

Use the exists function to check record's existence.

if ($reports->exists(['created >= ' => $date_one_month_ago_from_today]))
    //do something
} else
    //create a new financial report


Created: 10 Oct '16

Last Reply: 11 Oct '16

Replies: 1

Views: 4199

Votes: 0

Welcome to Aero Coding!

Aero Coding is a CakePHP-focused Q&A community for professional and enthusiast cake bakers. It's built and run by you as part of the community.

Join Now Tour

Download Cakephp

Start baking your own CakePHP application!

Cakephp All Versions