PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] Get all dates after current date CakePHP

 February 17, 2022     cakephp, date     No comments   

Issue

I have a question i want to get all the dates after the current date.

I use this code for that but it don't work.. can someone help me.

public function index() {
        $this->loadModel('wp_em_events');

        $date = date('d-m-Y');


        $this->set('wp_em_events',$this->wp_em_events->find('all', array(

            'conditions' => array(
                'wp_em_events.event_start_time >=' => date('Y-m'),
            )
        )));
    }

Solution

Your comment pointing to site nielsvandijkje.nl/demo doesn't reply how field event_start_time is defined in the db.

Still in your demo results are:

2014-07-04
2   Traditional music session   2013-02-17
3   6 Nations, Italy VS Ireland     2014-01-20

Query
SELECT [...] WHERE `event_start_time` >= '2014-07-04'

Since results with date 2013-02-17 and 2014-01-20 are returned it means that most probably the field isn't defined as a date and the db tries to compare strings which will fail to produce correct results.

So this doesn't seem like a cakephp issue but a DB issue. You can confirm it by running the raw SQL in phpmyadmin or mysql's CLI which should yield the same (wrong) results.



Answered By - user221931
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing