dbTalk Databases Forums  

[NOVICE] Julian date output?

mailing.database.pgsql-novice mailing.database.pgsql-novice


Discuss [NOVICE] Julian date output? in the mailing.database.pgsql-novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roy's Email
 
Posts: n/a

Default [NOVICE] Julian date output? - 07-15-2011 , 10:43 PM






I can see how to specify a Julian date, (J7395), but how do I get a "random" date converted to a Julian date? Do I need to do the calculation (from 4713 BC) myself?

On a related note, when taking the difference between two dates, how doI "force" the result to be in days (only)?

Thanks in advance.

Regards,

- Roy

=*=*=
Always do right.
This will gratify some people and astonish the rest. - Mark Twain

The truth is rarely pure, and never simple. - Oscar Wilde

Reply With Quote
  #2  
Old   
Greg Sabino Mullane
 
Posts: n/a

Default Re: [NOVICE] Julian date output? - 07-16-2011 , 06:48 AM






-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
NotDashEscaped: You need GnuPG to verify this message


Quote:
I can see how to specify a Julian date, (J7395),
but how do I get a "random" date converted to a Julian date?
Use the 'J' modifier of the built-in TO_CHAR function:

SELECT TO_CHAR(now(), 'J');

SELECT TO_CHAR(myfield, 'J') FROM mytable;

See:
http://www.postgresql.org/docs/curre...ormatting.html

If you are using this for astronomical purposes, keep in mind that
Postgres flips a Julian day at midnight, not noon!

If you are using this as a way to do arithmetic on dates, there
are much better ways:

Quote:
On a related note, when taking the difference between two dates,
how do I "force" the result to be in days (only)?
The result of subtracting two dates in Postgres is already
the number of days, as an integer, so one way is to simply force
the timestamps to dates first:

SELECT now()::date - '1970-01-01 12:34'::date
?column?
----------
15171
(1 row)

Alternatively, you can use the EXTRACT function:

SELECT EXTRACT('days' FROM (now() - '1970-01-01 12:34'::timestamp));
date_part
-----------
15170
(1 row)

Note the difference in result due to where the rounding occurs.

--
Greg Sabino Mullane greg (AT) turnstep (DOT) com
End Point Corporation http://www.endpoint.com/
PGP Key: 0x14964AC8 201107160740
http://biglumber.com/x/web?pk=2529DF...9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAk4hekcACgkQvJuQZxSWSsjsMwCfSPvbFguYWN nxe5ZCc95bHH71
CP0AoPIiR+9MkjQLsJrKnAMUWNa/3OZE
=Cx1n
-----END PGP SIGNATURE-----



--
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.