2

I need to update a date column value replace some string in replace the same value to date column.

Ex: Now date field have '2017-06-12 05:05:05' this value i need to replace this value to '2017-06-12'

I need query like update query

UPDATE student SET student_name = replace(student_name, 'John', 'Mark');
Deeban Babu
  • 729
  • 1
  • 15
  • 49
  • Its already in stackoverflow...https://stackoverflow.com/questions/10177208/update-a-column-value-replacing-part-of-a-string – Janen R Jun 13 '17 at 10:42

2 Answers2

2

Try this

 cast('2017-06-12 05:05:05' AS DATE)

output :- 2017-06-12

If you want replace then try this

 trim(replace('2017-06-12 05:05:05','05:05:05',''))

output :- 2017-06-12

1

Simply use CAST with UPDATE statement. Just insert your col name. You can cast field value to another type and assign to this field easily.

UPDATE
    student
SET
    <col_name> = CAST(<col_name> AS DATE)
WHERE
    <condition>
btlm
  • 353
  • 9
  • 17