Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Converting Julian Date into Date

Jun 1 2012 12:00AM by Madhivanan   

Julian date is one of the ways to represent date in number format. It is a 7 digit number with first four digits represents the year and last three digits represents the number of days since the first day of that year. There can be many methods to convert a Julian date to normal date. Here are some methods

Method 1 :  Extract numbers and use cast/convert function
declare @julian_date int = 2012146
select cast(left(@julian_date,4) as char(4))+dateadd(day,0,cast(right(@julian_date ,3) as int)-1)
Method 2 : My preferred method (not too many explicit convertions)
declare @julian_date int = 2012146
select dateadd(year,@julian_date/1000%10000-1900,0)+@julian_date%1000-1

Both methods return the following result
-----------------------
2012-05-25 00:00:00.000
Becuase the date is stored as number I will prefer applying more arithmetic operators than extrating number, casting to varchar and making a date. If you have more elegant method, Please post at comment section.

Tags: 


Madhivanan
3 · 39% · 12472
13
 
 
 
 
0
Incorrect



Submit

6  Comments  

  • Considering that even MS has used integer dates and times in MSDB, you'd think they'd have some native functionality that would more easily take care of such things.

    Nicely done on avoiding conversions to strings on this. They really can lend to a performace problem.

    As a side bar, you're good formula can be simplified a wee bit.

    declare @julian_date int = 2012060
    select dateadd(year,@julian_date/1000-1900,-1)+@julian_date%1000
    

    For those still using 2005, same thing... just a different test setup.

    declare @julian_date int 
    SELECT @Julian_Date = 2012060
    select dateadd(year,@julian_date/1000-1900,-1)+@julian_date%1000
    
    commented on Jun 1 2012 8:42AM
    Jeff Moden
    160 · 1% · 298
  • Heh... seriously??? I mispelled "times" as "timesd", corrected it, and that drives the post into moderation? Seriously? ;-)

    commented on Jun 1 2012 8:44AM
    Jeff Moden
    160 · 1% · 298
  • Jeff Moden

    Thanks for the feedback. Indeed %1000 is not needed.

    commented on Jun 2 2012 12:25PM
    Madhivanan
    3 · 39% · 12472
  • You bet, ol' friend.

    BTW... I just wanted to say "thank you" for all you've done for folks over the years on forums and in your blogs. You've definitely one of the good guys and I'm proud just to know you. Thanks, Madhivanan!

    commented on Jun 2 2012 3:44PM
    Jeff Moden
    160 · 1% · 298
  • Jeff Moden

    Thanks for your kind words. I feel very happy when I get such a feedback from you. You are the legend with so much of experience in the technology. Considering your vast experience I am very happy to hear feedbacks from you. Whenever there is a feedback from you I can gaurantee that someone will learn something new. I have learnt a lot from you right from where I came to know your knowledge in belutions.com Your posts on avoiding RBAR, clever usage of Tally number table, Quirky update technique and Running total are very popular that are referenced everywhere. You have very significant contributions to SQL Server. Keep up your good work.

    commented on Jun 3 2012 5:48AM
    Madhivanan
    3 · 39% · 12472
  • Look to the West and you'll see the glow from me blushing. Thanks Madhivanan.

    commented on Jun 3 2012 9:51AM
    Jeff Moden
    160 · 1% · 298

Your Comment


Sign Up or Login to post a comment.

"Converting Julian Date into Date" rated 5 out of 5 by 13 readers
Converting Julian Date into Date , 5.0 out of 5 based on 13 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]