-7

I have 2 fields dateUS and HourMins (data type is varchar)

dateUS     | HourMins

20160928   | 0108

20160927  | 2144

20160902 |  0319

20160919  | 1215

output will be

dateLoc    

20160928

20160928

20160902

20160920

run to mysql query on my database

1000111
  • 13,169
  • 2
  • 28
  • 37
odong
  • 13
  • 4

1 Answers1

0

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
1000111
  • 13,169
  • 2
  • 28
  • 37