Jump to content

STR_TO_DATE


yzerman

Recommended Posts

I have a query that keeps failing.

 

I am using Mysql version 5.0.24a

 

Here is the table setup:

 

+---------------------+-------------------+

| date (timestamp)      | time (varchar 255) |

+---------------------+-------------------+

| 2008-04-25 00:00:00 | 10:00AM              |

+---------------------+-------------------+

 

Now the query:

SELECT *,STR_TO_DATE(meta_title, '%h:%m%p') as time, DATE_FORMAT(date, "%Y-%m-%d') from content ORDER BY DATE_FORMAT(date, '%Y-%m-%d'), STR_TO_DATE(time, '%h:%m%p') ASC

 

Ok, now I have rows with:

 

07:45AM

10:00AM

12:00PM

12:15PM

10:00PM

10:45PM

 

The rows that are on the hour, return as a properly formatted timestamp (10:00AM)

The rows that are inbetween hours, return as null strings.

 

Modifying the table structure is not possible, neither is storing the time in the date timestamp.

 

Is this a bug in MySQL or am I doing something wrong?

Link to comment
https://forums.phpfreaks.com/topic/102972-str_to_date/
Share on other sites

The date (timestamp %Y-%m-%d) and time (%h:%m%p). I thought that was obvious by the query.

 

Basically the problem I am running into is when I sort by the date, the time field does not get sorted. So I tried to sort by the date (as shown in the query) and the time (meta_title or time, I screwed up the query) so that events on the same date would be arranged by time (12AM to 12PM to 11:59PM)

Link to comment
https://forums.phpfreaks.com/topic/102972-str_to_date/#findComment-530562
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.