Lee posted on September 25, 2009 08:17

JD Edwards friendly. 

Searching for “Date to Julian” on Google! will return 7,343,555 hits on a good day, but while such a cornucopia of awe-inspiring functions, scripts, and stored procedures are returned, I stil find that for JD Edwards this one works very well. I have no idea where I got this, but check it out and see if it doesn't do the job.  

 

SET ANSI_NULLS OFF

GO

SET QUOTED_IDENTIFIER ON

GO

 

CREATE FUNCTION [dbo].[dm_StdDate2Julian] (@stdDate datetime)

RETURNS bigint AS

BEGIN

       DECLARE @yy int

              ,@jyr char(3)

              ,@jday char(3)

              ,@jStr char(6)

              ,@dayOneStr char(10)

              ,@dayOne datetime

      

       /* Set julian year string */

       SET @yy = DATEPART(yy, @stdDate)

       IF (@yy > 1999)

              SET @jyr = '1' + RIGHT(STR(@yy),2)

       ELSE

              SET @jyr = RIGHT(STR(@yy),2)

      

       /* Set julian day string */

       SET @dayOneStr = '01/01/' + LTRIM(CONVERT(char(4),@yy))

       SET @dayOne = CONVERT(datetime, @dayOneStr)

       SET @jDay = CONVERT(varchar(3),CONVERT(int,(@stdDate - @dayOne+1)))

       IF LEN(@jDay) = 2

              SET @jDay = '0' + @jDay

       ELSE IF LEN(@jDay) = 1

       SET @jDay = '00' + @jDay

 

       SET @jStr = RTRIM(@jYr)+@jDay

      

       RETURN CONVERT(bigint, @jStr)

END

 

GO

 

Lee

 

 

----------------------- 

So how many WebsiteSpark blogs can be posted in one day?
 

 

http://planetsmilies.net/not-tagged-smiley-10244.gif

 

 

 


blog comments powered by Disqus

by Lee Everest, M.S.

Poll

Do you use Azure or cloud in your organization?



Show Results

Ads

Search


Month List

Calendar

«  February 2012  »
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011
View posts in large calendar

Tags

Disclaimer
The opinions, code, examples, et.al. expressed herein are my own personal opinions and do not represent my employer's view in any way, shape form, or fashion.  All code for demonstration purposes - no guarantees, either written or implied, are made.

© Copyright 2012 Lee Everest's SQL Server, etc. weblog