?
Solved

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

Posted on 2014-08-14
3
Medium Priority
?
1,123 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 51

Accepted Solution

by:
Vitor Montalvão earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

762 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