我有一个带有日期列的MySQL表。用户可以输入日期如下:
*thurs 4-21
*wed 4-28
*mon 5-5
*fri 5-17
但按任何顺序。当我将值从表中取出来时,可以按日期的编号部分进行排序吗?
我正在使用PHP。
发布于 2014-08-24 07:05:36
尝试以下概念:
SELECT
*
FROM
YOUR_TABLE
ORDER BY
STR_TO_DATE
(
CONCAT
(
'2014-',
SPLIT_STR(Your_Date_Field, ' ', 2) /* This will get the part of your string that is after the space */
) /* This will generate a string looks like this: 2014-4-21 */
,'%y-%m-%d'
); /* Convert the whole string to date using the format '%y-%m-%d' */
发布于 2014-08-24 05:32:27
是的你可以。从表中获取结果数据后,将其放入数组中。然后从后面进行访问,并根据需要对数据进行处理。最好将中间数据放到另一个时态数组中。
https://stackoverflow.com/questions/25468755
复制相似问题