vinoli
vinoli

Reputation: 457

Update time on timestamp column

I'm trying to select with reference to one column changing its time in MySQL, but I don't know how. How will I do it?

Example:

Time original: 2015-07-20 22:10:52
Updated: 2015-07-20 23:59:59

Upvotes: 1

Views: 6109

Answers (4)

Hard_Coder
Hard_Coder

Reputation: 848

UPDATE mytable SET mytimestamp = mytimestamp::date + '23:59:59'::time;

it should work.

Upvotes: 0

Mureinik
Mureinik

Reputation: 311326

You can use timestamp to join the current timestamp's date with the time you want to set:

UPDATE mytable
SET    mytimestamp = TIMESTAMP(DATE(mytimestamp), '23:59:59')

Upvotes: 2

LeleDumbo
LeleDumbo

Reputation: 9340

To update with no reference to previous column value, it's no different from other columns. To update with it, and based on certain part (second, month, year, whatever), you can use DATE_ADD or DATE_SUB function. Any other function in the same page might be useful, too, depending on your needs.

Upvotes: 1

Hitokage
Hitokage

Reputation: 803

It doesn't matter what type of column you have, your table can be modified with a standard UPDATE statement. You can also use the some special time/date functions to help you get the right format.

Upvotes: 0

Related Questions