Solved

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

Posted on 2014-08-14
3
949 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
3 Comments
 
LVL 65

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 45

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now