Solved

T-SQL Date to Julian Conversion

Posted on 2003-11-25
6
1,341 Views
Last Modified: 2009-01-27
Using T-SQL how can a date field (mm/dd/yyyy) be converted to a Julian Day Number?
0
Comment
Question by:jlindeman
6 Comments
 
LVL 5

Accepted Solution

by:
snimmaga earned 64 total points
ID: 9819360
0
 
LVL 6

Assisted Solution

by:lausz
lausz earned 62 total points
ID: 9819479
0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 62 total points
ID: 9820067
Try this:

DECLARE @date SMALLDATETIME
DECLARE @julDate INT
SET @date = '2003-11-25'

SET @julDate = YEAR(@date) * 1000 +
      DATEDIFF(DAY, CAST(YEAR(@date) AS CHAR(4)) + '-01-01', @date) + 1

SELECT @julDate


Didn't know if you wanted if YYDDD or YYYYDDD, so used YYYY.
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 62 total points
ID: 9820590
Hi jlindeman,

Declare @jd int
set @Jd = Year(@date) * 1000 + Datepart(dy,@date)



Cheers!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now