Forum OpenACS Q&A: Julian dates in PG

Collapse
Posted by Paul Doerwald on

I'm working on porting some Oracle code, and the code is heavily dependent on julian dates.

Postgres is great at converting ANSI dates to Julian, but doesn't appear to have a facility for converting Julian to ANSI -- at least none that I can see. Whatever I've tried either comes up with an error, or an 'invalid' result.

The calendar_convert_julian_to_ansi function that Don ported doesn't appear to work. Don's comment in ad-calendar- widget.tcl says that his code (which merely returns the $date variable passed in) should work because PG handles dates internally in Julian format. It doesn't.

Here's a little example of one of the problems I get at the psql command line:

dbase=> select to_timestamp (2451808,'J');
ERROR:  to_datatime(): J is not supported

Thanks for the help..

Collapse
Posted by Ben Adida on
Look at the file www/doc/sql/postgres.sql in OpenACS. It contains a function to_date_from_julian that we use to fix this issue.