Solved

reverse the date in find

Posted on 2014-10-09
7
104 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
ID: 40370640
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
ID: 40372831
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
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')  )); 
var_dump($dateoptions);

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

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

Accepted Solution

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

Expert Comment

by:Ray Paseur
ID: 40408224
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
ID: 40416993
i found the answer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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 the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

863 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

25 Experts available now in Live!

Get 1:1 Help Now