Solved

Changing the time value of a sql datetime

Posted on 2007-11-16
5
4,072 Views
Last Modified: 2008-02-01
Hi How can I set just the time value of a datetime:

for example

DECLARE @ENDDATE SMALLDATETIME
SET @ENDDATE = GETDATE()

If i wanted to then amend the time value of @ENDDATE, how would I do this?
0
Comment
Question by:scm0sml
[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
  • 3
5 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20297597
select CONVERT(varchar,getdate(), 108)
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20297602
make sure that you store that value in a Varchar column
declare @Time = varchar(10)
select @Time = CONVERT(varchar,getdate(), 108)
0
 

Author Comment

by:scm0sml
ID: 20297618
say i have

SET @TESTDATE = GETDATE()

That will give me the date and time for now.

But say I wanted to set the time value of @TESTTIME to 09:30 for example.

How can i do this?
0
 
LVL 25

Assisted Solution

by:imitchie
imitchie earned 100 total points
ID: 20297621

DECLARE @ENDDATE SMALLDATETIME
SET @ENDDATE = GETDATE()
 
set @change smalldatetime set @change = '12:30:12'
set @endDate = convert(datetime,
 convert(varchar, @endDate, 102) + ' ' + convert(varchar, @change, 8))

Open in new window

0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 400 total points
ID: 20297633
scm0sml,



Aneesh R

select CAST(CONVERT(varchar,getdate(), 112)   +' ' +'09:30'AS DATETIME)

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

728 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