Results 1 to 4 of 4

Thread: Next 21st

  1. #1
    Join Date
    Sep 2002
    Posts
    218

    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

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    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

  3. #3
    Join Date
    Sep 2002
    Posts
    218

    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.

  4. #4
    Join Date
    Dec 2004
    Posts
    502
    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
  •