Cómo comparar dos fechas en Cakephp según el día, el mes y el año

I have a (hopefully) quick question. I have two dates stored in a database, ['Event]['start_time'] and ['Event']['end_time']. I want to compare the dates to see if they match based on day, month, and year, disregarding the hours, minutes, and seconds they were created. How do I pick out the details of my dates when they're in this format?

preguntado el 09 de marzo de 12 a las 16:03

1 Respuestas

Are you trying to pull results where the start and end time match? You can do it like this:

$results = $this->Event->find('all',array('conditions' => 'DATE(Event.start_time) = DATE(Event.end_time)'));

DATE() is a MYSQL function that will just return the date in YYYY-MM-DD format and drop the time portion.

If you already have the data selected and want to compare it later, you can use the php functions date() y strtotime() Me gusta esto:

if(date('Y-m-d',strtotime($start_date)) == date('Y-m-d',strtotime($end_date))) {
    //dates are equal

dónde $start_date is ['Event']['start_time'] y $end_date is ['Event']['end_time']

respondido 09 mar '12, 16:03

That second part was exactly what I'm looking for. Thanks! - rasc0nza

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.