Solved

reverse the date in find

Posted on 2014-10-09
7
102 Views
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')  ));
0
Comment
Question by:jagguy
  • 4
  • 3
7 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Not sure about the "Cake" part, but in PHP we use strtotime() and date() functions to reformat dates.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Example:

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

Open in new window

0
 

Author Comment

by:jagguy
Comment Utility
The cake part is the MVC and this is important.
I meant getting the date reversed in the find itself
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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')  )); 
var_dump($dateoptions);

Open in new window

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:jagguy
Comment Utility
sorry I have been away for w awhile so I will get on to it
0
 

Accepted Solution

by:
jagguy earned 0 total points
Comment Utility
$sdate= date('d-m-Y',(strtotime( $sdate )));
echo $sdate;
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Are you sure there was nothing in this comment that helped you?
http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28534478.html#a40370640
0
 

Author Closing Comment

by:jagguy
Comment Utility
i found the answer
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now