Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4078
  • Last Modified:

Changing the time value of a sql datetime

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
scm0sml
Asked:
scm0sml
  • 3
2 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
select CONVERT(varchar,getdate(), 108)
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
make sure that you store that value in a Varchar column
declare @Time = varchar(10)
select @Time = CONVERT(varchar,getdate(), 108)
0
 
scm0smlAuthor Commented:
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
 
imitchieCommented:

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
 
Aneesh RetnakaranDatabase AdministratorCommented:
scm0sml,



Aneesh R

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

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now