Need Help with Julian date 90 days after the first of the next month

  • I tried many of the solutions posted but I have had no luck.
    I'm using  SQL Server Management Studio SQL Server 2012
    I'm trying to get the Juliandate: 90 days after the first of the next month?
    I was asked to do this so the user won't need to enter any dates manually....

    I need the 1st of next month (2018335) and 90 days after (2019060)

    Today is Nov 19, 2018 I use:

    Declare @currentDate Date

    Set @currentDate =  CAST(Getdate() as Date)

    Select  datepart(year, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) ) * 1000 + datepart(dy, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) ) -- This works and I get the 1st of next month Julian date

    Select

    datepart(year, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) ) * 1000 +90 + datepart(dy, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) )

    --This gives me “2018425” not “2019060”



  • davebozy - Monday, November 19, 2018 10:40 AM

    I tried many of the solutions posted but I have had no luck.
    I'm using  SQL Server Management Studio SQL Server 2012
    I'm trying to get the Juliandate: 90 days after the first of the next month?
    I was asked to do this so the user won't need to enter any dates manually....

    I need the 1st of next month (2018335) and 90 days after (2019030)

    Today is Nov 19, 2018 I use:

    Declare @currentDate Date

    Set @currentDate =  CAST(Getdate() as Date)

    Select  datepart(year, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) ) * 1000 + datepart(dy, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) ) -- This works and I get the 1st of next month Julian date

    Select

    datepart(year, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) ) * 1000 +90 + datepart(dy, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) )

    --This gives me “2018425†not “2019030â€



    2019030 would only be 60 days not 90 days.  How about the following to help you get started?

    Declare @currentDate Date

    Set @currentDate = CAST(Getdate() as Date)

    select
    dateadd(day,1,eomonth(@currentDate))
    ,year(dateadd(day,1,eomonth(@currentDate))) * 1000 + datepart(dayofyear,dateadd(day,1,eomonth(@currentDate)))
    ,year(dateadd(day,91,eomonth(@currentDate))) * 1000 + datepart(dayofyear,dateadd(day,91,eomonth(@currentDate)));

  • davebozy - Monday, November 19, 2018 10:40 AM

    I tried many of the solutions posted but I have had no luck.
    I'm using  SQL Server Management Studio SQL Server 2012
    I'm trying to get the Juliandate: 90 days after the first of the next month?
    I was asked to do this so the user won't need to enter any dates manually....

    I need the 1st of next month (2018335) and 90 days after (2019060)

    Today is Nov 19, 2018 I use:

    Declare @currentDate Date

    Set @currentDate =  CAST(Getdate() as Date)

    Select  datepart(year, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) ) * 1000 + datepart(dy, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) ) -- This works and I get the 1st of next month Julian date

    Select

    datepart(year, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) ) * 1000 +90 + datepart(dy, DATEADD(m, DATEDIFF(m, -1, @currentDate), 0) )

    --This gives me “2018425†not “2019060â€



    Found a solution:

    Declare @currentDate90 Date

    Set @currentDate90 = CAST(Getdate()+90 as date

    )
    Select

    datepart

    (year, DATEADD(m, DATEDIFF(m, -1, @currentDate90), 0) ) * 1000 + datepart(dy, DATEADD(m, DATEDIFF(m, -1, @currentDate90), 0) )

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply