Solved

update time in datetime column  - replace

Posted on 2015-01-31
2
115 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

     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 …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

696 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