Mysql: Editing only the date in datetime

Recently I was looking for a way to do data testing in my project which involves data with date time. Since it was querying for the current day and my data was older, I wanted to change the date part of the datetime column. Anyways, here is how I did it:

UPDATE tablename SET fieldname = concat('2015-04-14 ', time(fieldname)) WHERE DATE(fieldname) = '2015-04-10'

‘2015-04-14’ is the new date we want to apply and ‘2015-04-10’ is the old date that we want to look for.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s