reverse the date in find

Posted on 2014-10-09
Last Modified: 2014-11-01
Hi, In cakephp how can I get the date in reverse order as when I add this to a select input box I see the date as Y-m-d.
The database stores the date in this order.
In the find I want to have the date formatted before assigning to a select box.

  $dateoptions=$this->Lesson->find('list', array(
               'fields' => array('Lesson.lesson_date')  ));
Question by:jagguy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 110

Expert Comment

by:Ray Paseur
ID: 40370640
Not sure about the "Cake" part, but in PHP we use strtotime() and date() functions to reformat dates.


$today = '2014-10-08';
$timestamp = strtotime($today);
$pretty_date = date('F j, Y', $timestamp);

Open in new window


Author Comment

ID: 40372831
The cake part is the MVC and this is important.
I meant getting the date reversed in the find itself
LVL 110

Expert Comment

by:Ray Paseur
ID: 40373317
I understand that Cake is the MVC framework.  I don't think you can do the date "reversal" in the find().  It's a bit of an exploratory process, but if you work with me we can get a good solution.  After this function call, please add var_dump() as shown here.  Use "view source" to see the output from var_dump().  Copy it and post it back here, thanks.  Also, please tell me the format you want to see for the date.

$dateoptions=$this->Lesson->find('list', array(
               'fields' => array('Lesson.lesson_date')  )); 

Open in new window

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.


Author Comment

ID: 40389466
sorry I have been away for w awhile so I will get on to it

Accepted Solution

jagguy earned 0 total points
ID: 40407669
$sdate= date('d-m-Y',(strtotime( $sdate )));
echo $sdate;
LVL 110

Expert Comment

by:Ray Paseur
ID: 40408224
Are you sure there was nothing in this comment that helped you?

Author Closing Comment

ID: 40416993
i found the answer

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question