Solved

update time in datetime column  - replace

Posted on 2015-01-31
2
104 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:
SimonAdept 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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