Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

T-SQL Date to Julian Conversion

Posted on 2003-11-25
6
Medium Priority
?
1,368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Accepted Solution

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

Assisted Solution

by:lausz
lausz earned 248 total points
ID: 9819479
0
 
LVL 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 248 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 248 total points
ID: 9820590
Hi jlindeman,

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



Cheers!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

650 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