• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Convert Date functions to valid dates in SQL Server ?

Could you tell me how to convert the following 2 Date functions into valid SQL Server statements ?

1) DateAdd("m",[MthTo]*-1,Date()-DatePart("d",Date()-1)) AS DateFromC,

2) DateDiff("m",[DateLost],Date()-DatePart("d",Date()-1))>=[MthFrom]

Would it be something close to the following:

1) DateAdd('m',[MthTo]*-1,DateAdd(DD, DatePart(DD, GetDate() -1) * -1, GetDate())

2) DateDiff('m',[MthTo]*-1, DateAdd(DD, DatePart(DD, GetDate() -1) * -1, GetDate())

0
zimmer9
Asked:
zimmer9
1 Solution
 
rafranciscoCommented:
Try this:

1) DateAdd("m",[MthTo]*-1,Date()-DatePart("d",Date()-1)) AS DateFromC

DATEADD(M, [MthTo] * -1, DATEADD(DD, (DATEPART(DD, GETDATE()) - 1) * -1, GETDATE()))

2) DateDiff("m",[DateLost],Date()-DatePart("d",Date()-1))>=[MthFrom]

DATEDIFF(M, [DateLost], DATEADD(DD, (DATEPART(DD, GETDATE()) -1) * -1, GETDATE())) >= [MthFrom]
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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