Solved

Changing the time value of a sql datetime

Posted on 2007-11-16
5
4,066 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

911 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

26 Experts available now in Live!

Get 1:1 Help Now