Skip navigation

Does SQL Server have any built-in functions to work with julian dates?

A. No, you have to code your own sp. Here is some sample code - originally from Roy Harvey.

  1. Assuming the Julian date is held as a char
    declare @julian char(8)
    select @julian='1996.031'
    declare @dt datetime

    select @dt=DATEADD(dd,convert(int,right(@julian,3)) -1,convert(datetime,substring(@julian,1,4)+'0101',212))

    select @dt
  2. Julian date in decimal format - e.g. 99123 is 123rd day of 1999 held in variable SDDRQJ.
    select DATEADD(day,CONVERT(int,SDDRQJ)-((1000*(CONVERT(int,SDDRQJ)/1000)))-1, DATEADD(year,CONVERT(int,SDDRQJ/1000),'1 Jan 1900'))

TAGS: SQL
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish