-
Next 21st
I Have a date called DateApproved. I want to get the Next 21st After DateApproved per Loan.
How do I achieve this.
Select
Case
When DatePart(Day ,e.DateApproved) < 21 And
Datepart(Month,e.DateApproved) = Month(getdate())
Then Substring(Convert(Char(10),e.DateApproved,120),1,4 ) +
Substring(Convert(Char(10),e.DateApproved,120),6,2 ) + '21'
When DatePart(Day ,e.DateApproved) >= 21 And
Datepart(Month,e.DateApproved) = Month(getdate())
Then Substring(Convert(Char(10),e.DateApproved,120),1,4 ) +
Convert(Dateadd(Month,e.DateApproved,1),Char(2)) + '21'
End AS 1stDueDte
From
Test e
-
Here is one way. I wasn't sure what you wanted to do if the DateApproved fell exactly on the 21st, so you might have to change the "<=" to "<":
SELECT
CASE WHEN DAY(DateApproved) <= 21 THEN DATEADD(m, DATEDIFF(m, 20, DateApproved), 20)
ELSE DATEADD(m, DATEDIFF(m, 20, DateApproved) +1, 20) END
FROM Test e
-
Next 21st
The scenario is if the date is between 1st Of June and 20th of June 2005 then The istDueDate will be the 21st of June 2005 but if its >= than 21st of June then The 1stDueDate Should be the 21st of the next month . ie. 21st of July 2005.
-
Well, then just change the "<=" in the above query to "<" and I believe it should be good to go.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|