Convert Julian Date to Normal Calendar Date

Moderator: NorbertKrupa

Post Reply
User avatar
janice
Intermediate
Intermediate
Posts: 51
Joined: Wed May 30, 2012 1:14 pm

Convert Julian Date to Normal Calendar Date

Post by janice » Fri Mar 22, 2013 2:05 pm

Hi,

I am having trouble converting a Julian date back to a normal calendar date.

If I get the Julian Day for today:

Code: Select all

dbadmin=> SELECT sysdate, julian_day(sysdate);
          sysdate           | julian_day
----------------------------+------------
 2013-03-22 09:04:29.667331 |    2456374
(1 row)
I can't convert it back with the TO_DATE function:

Code: Select all

dbadmin=> SELECT to_date(2456374, 'J');
ERROR 3457:  Function to_date(int, unknown) does not exist, or permission is denied for to_date(int, unknown)
HINT:  No function matches the given name and argument types. You may need to add explicit type casts
What gives?
Last edited by janice on Fri Mar 22, 2013 3:44 pm, edited 1 time in total.
Everyday is an adventure!

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Convert Julian Date to Normal Date

Post by JimKnicely » Fri Mar 22, 2013 3:27 pm

Hi Janice,

The TO_DATE function with the "J" format string work's as expected in Oracle!

Code: Select all

SQL> SELECT to_date(2456374, 'J') "Gregorian" FROM dual;

Gregorian
---------
22-MAR-13
And from what I've read in the "Template Patterns for Date/Time Formatting" section of the Vertica SQL Reference Manual, I would also think the above command should work to in Vertica! But as you seen from your experience, it does not :roll:

But you can do something like this:

Code: Select all

dbadmin=> SELECT TIMESTAMPADD ( 'd', 2456374 - 2415021, '01/01/1900')::DATE "Gregorian";
 Gregorian
------------
 2013-03-22
(1 row)
In general:
  • TIMESTAMPADD ( 'd', :JULIAN_DATE - 2415021, '01/01/1900')::DATE "Gregorian";
I hope this helps!
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

User avatar
janice
Intermediate
Intermediate
Posts: 51
Joined: Wed May 30, 2012 1:14 pm

Re: Convert Julian Date to Normal Calendar Date

Post by janice » Fri Mar 22, 2013 3:45 pm

WOW, THANKS JIM!
Everyday is an adventure!

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Convert Julian Date to Normal Calendar Date

Post by JimKnicely » Fri Mar 22, 2013 4:30 pm

No problem!

FYI, check out the post "Converting to a Julian Date and Back Again!" here viewtopic.php?f=63&t=943!
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

User avatar
Julie
Master
Master
Posts: 221
Joined: Thu Apr 19, 2012 9:29 pm

Re: Convert Julian Date to Normal Calendar Date

Post by Julie » Fri Mar 22, 2013 7:49 pm

@janice - What's a "normal" calendar date? :lol:
Thanks,
Juliette

Post Reply

Return to “New to Vertica SQL”