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
Solved

T-SQL Date to Julian Conversion

Posted on 2003-11-25
6
1,352 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:Scott Pletcher
Scott Pletcher 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

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

856 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