PHP
--
Questions
--
Followers
Top Experts
Format: 03/11/2009 at 10:24:12 AM
I need to have it so the latest Date/Time shows on Top.
SQL: SELECT `Date`, FROM `TABLENAME` ORDER BY `Date` DESC
SQL Current Result:
03/11/2009 at 10:24:12 AM
03/11/2009 at 10:21:25 AM
03/11/2009 at 10:14:08 AM
03/11/2009 at 01:13:34 PM
SQL Expected Result:
03/11/2009 at 01:13:34 PM
03/11/2009 at 10:24:12 AM
03/11/2009 at 10:21:25 AM
03/11/2009 at 10:14:08 AM
If you need any additional information, please let me know.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
03/11/2009 at 01:13:34 PM
03/11/2009 at 10:14:08 AM
03/11/2009 at 10:21:25 AM
03/11/2009 at 10:24:12 AM
When I need it to be:
03/11/2009 at 01:13:34 PM
03/11/2009 at 10:24:12 AM
03/11/2009 at 10:21:25 AM
03/11/2009 at 10:14:08 AM
Notice the AM/PM Change. That might of threw you off :)






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Is it a VARCHAR? Also, how is the time being inserted into it? Is it just like what's being returned, or is the info you're showing us post-parsed into a readable format?
These functions are extremely useful, anyways- so you should learn them to buff up on parsing data with PHP :)
Link 1- use this to separate the time format you have into sections (month, day, hour, minute, am/pm, etc)
http://us2.php.net/manual/en/function.explode.php
Link 2- use this to change * AM to "0" and * PM to "+12" (hours) to convert the time to a univeral (24 hour, IE 13:45 instead of 1:45PM) time standard
http://us2.php.net/strrpos
Then make a basic variable to sort them.
I wish I could help more but I don't have that much time to commit, on top of my own project :/

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
select str_to_date( `Date`, "%m/%d/%Y at %h:%i:%s %p" ) as date1 from tablename order by date1 desc
I tried your solution, but no prevail. It returns rows, but the values are NULL.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
MySQL client version: 4.1.22
It works perfectly, then I just pass in the returned row value to the following function I created.
Final Solution:
// RUN QUERY
SELECT STR_TO_DATE(replace(`Date`," at ",""), "%m/%d/%Y %h:%i:%s %p" ) as DateAdd FROM `TABLENAME` ORDER BY `DateAdd` DESC
// WHILE LOOP
$strDateTime = FormatDateTime($Row["DateAdd"]);
function FormatDateTime($string) {
$strDate = substr($string,0,10);
$strTime = trim(substr($string,10));
list($strYear, $strMonth, $strDay) = explode('-', $strDate);
$strTime = date('g:i:s A' , strtotime($strTime));
$string = $strMonth . "/" . $strDay . "/" . $strYear . " at " . $strTime;
return $string;
}
SELECT str_to_date( replace( `rs_DateAdd` , ' at ', '' ) , '%m/%d/%Y %h:%i:%s %p' ) AS Date
FROM `TABLENAME`
WHERE `rs_ExtID` =79
ORDER BY `rs_DateAdd` DESC
Results:
Date
2009-03-12 09:52:22
2009-03-11 10:24:12
2009-03-11 10:21:25
2009-03-11 10:14:08
2009-03-11 13:13:34
2009-03-10 13:24:23
2009-03-10 13:23:08
2009-03-05 09:45:21
Am I thinking about this wrong? I need the date Descending, but the time from Latest to earliest.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
SELECT str_to_date( replace( `rs_DateAdd` , ' at ', '' ) , '%m/%d/%Y %h:%i:%s %p' ) AS Date
FROM `TABLENAME`
WHERE `rs_ExtID` =79
ORDER BY `Date` DESC
Thanks for the help!
FROM `TABLENAME`
WHERE `rs_ExtID` =79
ORDER BY `Date` DESC
PHP
--
Questions
--
Followers
Top Experts
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.