Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Posts
    20

    Angry Unanswered: Julian Date---help :(

    I have a julian date(04159) and I need to convert this to any normal date format yyyymmdd or mmddyy or basically anything that I can work with! I am just about fed up with trying to convert this. It would be simple enough if there want leap years. Does anyone have a function or something out there that can convert this for me? Code that I found on the web turned out to be bogus. Your help will be greatly appreciated. If you have something in VB that would work also. SQLServer preferably.

    Thanks

  2. #2
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    It may be off by a day or so, but it's a start:

    select dateadd(day, cast(reverse(cast(reverse('04159') as char(3))) as int), '01/01/' + cast('04159' as char(2)))
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  3. #3
    Join Date
    Feb 2004
    Posts
    20
    Yeah...Thats sorta where I left off in my efforts. Thanks for your input. I will eventually get it...Hopefully someone in here will see this and have something.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    This is ancient old code, from when SQL 2000 was still in beta, but I think it works. Give this a try:
    Code:
    CREATE FUNCTION dbo.f_jDate(@piJdate INT) RETURNS DATETIME AS
    BEGIN
       RETURN DateAdd(day, (@piJdate % 1000) - 1, Convert(DATETIME
    ,     CASE WHEN @piJdate < 50000 THEN '20' ELSE '19' END 
    +     Replace(Str(@piJdate / 1000, 2), ' ', '0') + '-01-01'))
    END
    -PatP

  5. #5
    Join Date
    Feb 2004
    Posts
    20
    Thanks Pat.....That worked perfectly! Your my hero for the day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •