-1

i have a column of Strings like 2015/10/14 07:00:00 i need to convert them to DateTime, my problem is :

07:00 is in pm time

i need to get that in a format of 19:00

my code:

UPDATE `DATE_tests`
      SET `newDate` = STR_TO_DATE(`oldDate`, '%Y/%m/%d %r')

to be precise i need 2015/10/14 07:00:00 to be 2015-10-14 19:00:00.

i can get so far 2015-10-14 07:00:00

Mounir Elfassi
  • 2,242
  • 3
  • 23
  • 38

2 Answers2

2

You should fix the table and store dates as dates, not as strings. But you need to add 12 hours to do what you want. Something like this

UPDATE `DATE_tests`
      SET `newDate` = DATE_FORMAT(DATE_ADD(STR_TO_DATE(`oldDate`, '%Y/%m/%d %r'), interval 12 hour), '%Y-%m-%d %H:%i:%s');
Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

try:INTERVAL 12 HOUR

UPDATE `DATE_tests`
      SET `newDate` = DATE_FORMAT(DATE_ADD(STR_TO_DATE(`oldDate`, '%Y/%m/%d %r'), INTERVAL 12 HOUR), '%Y-%m-%d %H:%i:%s');

see here:Add 2 hours to current time in MySQL?

Community
  • 1
  • 1
Suchit kumar
  • 11,809
  • 3
  • 22
  • 44