Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-02-15 : 22:26:49
|
| hiI am not able to add 1 hour. Here is the code:Declare @Appt_EndDate smalldatetime,@Appt_StartDate smalldatetimeset @Appt_StartDate = '2010-02-17 14:30:00'Set @Appt_EndDate = @Appt_StartDate + datepart(hh,@Appt_StartDate)+1select @Appt_StartDate,@Appt_EndDateThe end result should be '2010-02-17 15:30:00' but i am getting 2010-03-04 14:30:00What should i change in the code? Thanks a lot. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-02-15 : 22:57:05
|
[code]set @Appt_EndDate = dateadd(hour, 1, @Appt_StartDate)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-02-15 : 23:05:19
|
| Thanks a lot |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-16 : 01:01:35
|
| what @Appt_StartDate + datepart(hh,@Appt_StartDate)+1 does is to retrive hour part of date (which is 14) and add it as integer value to date and again another 1so result will be 14+1 15 days ahead of @Appt_StartDate which is what you got as 2010-03-04 14:30:00------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|