With the help of STR_TO_DATE
and DATE_FORMAT
function you can achieve this:
SELECT
DATE_FORMAT(STR_TO_DATE(dateUs,'%Y%m%d') + INTERVAL HourMins+0 >= 1200 DAY ,'%Y%m%d')
AS dateLoc
FROM your_table
Demonstration:
SET @str := '20160919';
SET @HOUR := '1215';
SELECT
(
STR_TO_DATE(@str, '%Y%m%d') + INTERVAL (@HOUR + 0) >= 1200 DAY
) AS date,
DATE_FORMAT(
STR_TO_DATE(@str, '%Y%m%d') + INTERVAL (@HOUR + 0) >= 1200 DAY,
'%Y%m%d'
) AS expectedFormat;
Output:
date expectedFormat
2016-09-20 20160920
solved add 1 day to date format YYYYMMDD when field name is greater or equal to 1200 [closed]