Solved

SQL Update Query - Change date ONLY in time/date field

Posted on 2014-08-14
3
1,082 Views
Last Modified: 2014-08-14
I need to change a bunch of rows that was dated 08/30/2014 to 05/31/2014 but I don't want to change the time stamp within the value.  So if the row shows 08/30/2014 00:30:27.513...I want the row to be updated to 05/31/2014 00:30:27.513
0
Comment
Question by:Lee R Liddick Jr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40260792
Hmm.  Very wild guess..
UPDATE your_table
SET the_datetime = CAST('2014-05-31 ' + CAST(the_datetime as time) as datetime)
WHERE CAST(the_datetime as date) = '2014-08-30'

Open in new window

>a bunch of rows that was dated 08/30/2014 to 05/31/2014
>So if the row shows 08/30/2014
Define this a little further for us please.
0
 
LVL 50

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40260798
Try this:

UPDATE TableName
SET MyDate = DATEADD(days, DATEDIFF(day,'08/30/2014','05/31/2014') , MyDate)
WHERE MyDate BETWEEN '08/30/2014' AND '08/31/2014'

Open in new window

0
 

Author Closing Comment

by:Lee R Liddick Jr
ID: 40260874
That was it...thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question