Hello guys, I need your help.
Are looking for easy solution, can you help me?
In remote dotable mysql I have this not normalized string in the field start:
1/1/2013 14:29:00
I need for this string calculate the WEEK and WEEKDAY.
I tried this query version, but the output WEEK and WEEKDAY is NULL:
SELECT
WEEK (
STR_TO_DATE(start, '%d/%m/%Y %H:%i'),
5
) AS strWeek,
weekday(
STR_TO_DATE(start, '%d/%m/%Y %H:%i')
) AS strWeekDay,
start AS start
FROM
(
SELECT
STR_TO_DATE(
start,
'%d/%m/%Y %H:%i'
) AS start
FROM
dotable
) AS qx;
I tried this version and the output WEEK and WEEKDAY is correct, but the query is long time:
SELECT
WEEK (
STR_TO_DATE(start, '%d/%m/%Y %H:%i'),
5
) AS strWeek,
weekday(
STR_TO_DATE(start, '%d/%m/%Y %H:%i')
) AS strWeekDay,
start AS start
FROM
(
SELECT
REPLACE (
IF (
mid(
IF (
mid(start, 2, 1) = '/',
concat('0', start),
start
),
5,
1
) = '/',
concat(
mid(
IF (
mid(start, 2, 1) = '/',
concat('0', start),
start
),
1,
3
),
'0',
mid(
IF (
mid(start, 2, 1) = '/',
concat('0', start),
start
),
4,
100
)
),
IF (
mid(start, 2, 1) = '/',
concat('0', start),
start
)
),
'.',
':'
) AS start
FROM
dotable
) AS qx;