2

I have a column in my table-TimeUpdated but the data coming to this column from source is in Julian datetime format.

I found this below query to convert the Date part of julian timestam to normal timestamp -

 declare @a as int = 2458228
 select @a, dateadd(d,@a - 2440588,'1970-01-01')

But i can't figure out how to convert the Hour-Minute-second part. Can anybody help? Thanks in advance.

P.S. - 2458228.05929 in Julian means 19-04-2018 18:55:20 IST. Also you can refer to this site which will convert any day to Julian Datetime - http://www.onlineconversion.com/julian_date.htm

Be1ng_Kr1Sh
  • 293
  • 2
  • 13

1 Answers1

2

If I am understanding correctly, then the correct expression would be:

DECLARE @a int = '2440588';
DECLARE @Julian decimal(16,5) = 2458228.05929;

SELECT DATEADD(DAY,CONVERT(int,@Julian) - @a, '19700101') +
       DATEADD(HOUR,12,DATEADD(SECOND,(60 * 60 * 24) * (@Julian - convert(int,@Julian)),0));

This gives the UTC time 2018-04-19 13:25:22.000 (which, if converted to IST (Indian Standard Time (UTC +5:30) for those who don't know their Timezones) is 2018-04-19 18:55:22.000.

Thom A
  • 88,727
  • 11
  • 45
  • 75