Solved

update time in datetime column  - replace

Posted on 2015-01-31
2
111 Views
Last Modified: 2015-01-31
Hello,

I have a table ADateTest. It has 2 columns Id(int)=1, MyDate(datetime)='2015-01-31 14:06:00.000'

I try to update like this and nothing happens.
update ADateTest SET MyDate=REPLACE(MyDate,'14:06','15:10')

How can I update the DateTime column so it will be '2015-01-31 15:10:00.000' instead of '2015-01-31 14:06:00.000'
0
Comment
Question by:johnson1
2 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40581378
You can set it directly using a datetime literal string:
UPDATE ADateTest
set MyDate='20150131 15:10'
WHERE ID=1

Open in new window


or by adding or subtracting from the current value using the dateadd function:
UPDATE ADateTest
set MyDate=DATEADD(minute,64,MyDate)
WHERE ID=1

Open in new window


The REPLACE function only works on string values. You could cast/convert your datetime column to a string and then use the replace function, but I wouldn't suggest it as a method.
0
 

Author Closing Comment

by:johnson1
ID: 40581404
Thank you.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query 8 51
Challenging SQL Update 5 49
MS SQL 2008 Divide by zero error encountered. Error 3 45
SQL Server 2012 r2 - Sum totals 2 28
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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