Julian to Calendar?

  • Good utilities are posted here to convert Calendar dates to Julian.  Does anyone have a nice TSQL function to convert Julian dates to Calendar? 

    Depend upon it, sir, when a man knows he is to be hanged in a fortnight,

    it concentrates his mind wonderfully."

    Samuel Johnson

    When the snows fall and the white winds blow,The lone wolf dies but the pack survives.

    Once you've accepted your flaws, no one can use them against you.

  • declare @Julian int

    select @Julian = datepart(dayofyear, '2005-08-01')

    Select dateadd(dd, @Julian, '12-31-2004')as stdDate, @Julian as JulianDte


    * Noel

  • That works, but I need a 2 digit year in front. 

    When the snows fall and the white winds blow,The lone wolf dies but the pack survives.

    Once you've accepted your flaws, no one can use them against you.

  • Sorry that wasn't really necessary.  Excuse the space.

    When the snows fall and the white winds blow,The lone wolf dies but the pack survives.

    Once you've accepted your flaws, no one can use them against you.

  • Amending noeld's post ... is this what you mean?  I don't like 2 digit years!  The coding works only for the 21st Century.  It's fairly easily modified to handle a different 100 yr range (eg 1960-2059)

    declare @Julian varchar(10)
    select @Julian = '04-213'
    declare @lastdayprevyr datetime
    select @lastdayprevyr = dateadd(year,-1,convert(datetime,'31-Dec-20'+substring(@Julian,1,2)))
    select dateadd(day,convert(int,substring(@Julian,4,99)),@lastdayprevyr) as stdDate
    
    stdDate
    2005-08-01 00:00:00.000

Viewing 5 posts - 1 through 4 (of 4 total)

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