Solved

update time in datetime column  - replace

Posted on 2015-01-31
2
113 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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server 2012 r2 - Varible Table 3 39
Add a step to a system backup job 6 30
sql 2016 data tools breakdown.. 1 25
SQL QUERY 3 33
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Detach & Attach 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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 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