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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Adding Days to Date

Author  Topic 

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2014-09-04 : 10:46:36
Hi All
Need help with DATEADD function as i'm running into an error
Below is my SQL to derive start date of a month based on deliververydate feild.I'm running into error when i try to add 25 days to the start date of the month.

DATEADD(m,DATEDIFF(m,0,convert(varchar(30),DATEADD (month , @count*3 ,SR.DeliveryDate))),0)


When i want to add 25 days to the start date of a month getting an error
Error SQL

DateAdd(day,(DATEADD(m,DATEDIFF(m,0,convert(varchar(30),DATEADD (month , @count*3 ,SR.DeliveryDate))),0)),25)



Error Message
Argument data type datetime is invalid for argument 2 of dateadd function.

What do i need to change to make it work
Thanks in advance

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-09-04 : 11:28:58
You have the order reversed for parameters 2 and 3[CODE]DateAdd(day,25,(DATEADD(m,DATEDIFF(m,0,convert(varchar(30),DATEADD (month , @count*3 ,SR.DeliveryDate))),0)))[/CODE]



Too often we enjoy the comfort of opinion without the discomfort of thought. - John F. Kennedy
Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2014-09-04 : 17:01:21
Thanks a Lot
quote:
Originally posted by Bustaz Kool

You have the order reversed for parameters 2 and 3[CODE]DateAdd(day,25,(DATEADD(m,DATEDIFF(m,0,convert(varchar(30),DATEADD (month , @count*3 ,SR.DeliveryDate))),0)))[/CODE]



Too often we enjoy the comfort of opinion without the discomfort of thought. - John F. Kennedy

Go to Top of Page
   

- Advertisement -