update time in datetime column  - replace

Posted on 2015-01-31
Last Modified: 2015-01-31

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'
Question by:johnson1
LVL 18

Accepted Solution

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

Open in new window

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

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.

Author Closing Comment

ID: 40581404
Thank you.

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 159
Row-Level Security 2 32
all records from previous month 6 45
Find data in a column which is not in  a date format 29 0
Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

13 Experts available now in Live!

Get 1:1 Help Now