Reputation: 43
I am trying to update the filed date in mysql database , this field contains unix-timestamp date.
But I do not want to convert the whole of date 1364562954
, I want to replace only the year and leave the day, month and time same.
For Example - 19-03-2015, 03:43 PM
to 19-03-2016, 03:43 PM
Upvotes: 1
Views: 3404
Reputation: 24551
You can use FROM_UNIXTIME
and UNIX_TIMESTAMP
to convert a Unix timestamp to MySQL's DATETIME
format.
So for example to get a timestamp incremented by one year:
SELECT UNIX_TIMESTAMP(FROM_UNIXTIME(1364562954) + INTERVAL 1 YEAR);
Result: 1396098954
For UPDATE
it is the same:
UPDATE t SET tstamp= UNIX_TIMESTAMP(FROM_UNIXTIME(tstamp) + INTERVAL 1 YEAR);
Reference: Date and Time Functions
Upvotes: 2