LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   date in julian format (https://www.linuxquestions.org/questions/linux-newbie-8/date-in-julian-format-668827/)

nanda22 09-10-2008 12:38 AM

date in julian format
 
Hi

I want the current date in julian format stored into one variable.
Please help me

chrism01 09-10-2008 01:02 AM

Depends on which one: http://en.wikipedia.org/wiki/Julian_day
but seconds since 1970 (aka Unix epoch) is date %s, see man date.
%j day-of-yr

pinniped 09-10-2008 01:27 AM

There is only ONE Julian Day (aka Julian Date). The day-of-year thing is bullshit (although, unfortunately, very commonly accepted bullshit) - that is NOT a Julian date - that is what some ignoramuses (ignorami?) from the management world called the day-of-year (Ordinal Day of Year, as accepted in the ISO terminology), so parroting that is promoting ignorance and confusion as to what a Julian date is.

Anyway, this link may get you started:

http://aa.usno.navy.mil/data/docs/JulianDate.php

The US Naval Observatory also has other useful web pages discussing time, but I can't seem to find them at the moment. Just to confuse things, some of the positive dates in the Julian Date system actually preceed the use of the Julian Calendar, and these are known as the Proleptic Julian Dates. In a similar fashion, dates written as a Gregorian Date but before the establishment of the Gregorian Calendar (such as dates typically quoted in history books) are proleptic Gregorian dates.

So if you really want Julian Dates, you need to read a bit about the history of time and look up conversions. If you can get a copy of a current edition of the Royal Astronomical Almanac, you may find a simple calculation of the Julian Date referenced to a more recent epoch; if you want something more accurate (not made obsolete in the near future or past) you will need to do a lot more reading.

chrism01 09-10-2008 01:56 AM

Easy Tiger, I was just pointing out his options. That also includes the Wiki page which points out various 'definitions' of such 'dates' and the history thereof, inc links to eg USN Observatory.
:)
You don't know which one he actually wants.

AnanthaP 09-10-2008 08:39 AM

You know the old poem:

30 days hath September, April, June and November,
All the other days but February have 31,
February has 28 unless its a leap year.

Build these datas into an array.

Its possible to so given an year, you determine whether its a leap year or not.
Then offset days for the elapsed months, (Jan 0, Feb 31 ..)
Add days in the current month.

There is the same example in K&R (in C).
It can be easily written in any other programming language and also in shell script also.

End

GazL 09-10-2008 11:36 AM

Even big technology players like IBM refer to ordinal dates as 'julian date format'. YY.DDD was a very common format on their MVS mainframes and probably still is. It's a little harsh to call it 'bullshit'. It's actually a very useful date format. Far more useful than the number of days from some ancient epoch for most uses, unless you're doing something with astronomical data when an ancient epoch is probably quite vital.

I think its a pretty safe bet what he's looking for is the more commonly (if incorrectly) used meaning,

date +%Y-%j is most likely the correct answer in this case.


Anyway, could be worse, if it was based on the Chinese year then today would be
"Rat-216"

;)

bibh_lnxq 09-10-2008 12:07 PM

[QUOTE=pinniped;3275435]
Quote:

Originally Posted by pinniped (Post 3275435)
ignoramuses (ignorami?)

Off topic, I know, but I cannot resist.;)
ignoramus = "we know not", sometimes "we do not want to know".
There is no Latin plural of ignoramus; it is a (non-nominal) form of a verb and it is not the same -us as in fungus.
Your "ignoramuses" is right.

Wastrel 09-03-2012 11:18 AM

Good heavens
 
Why are the answers to this so peculiar? Why send the questioner to the Naval Observatory or tell him to build an array...? Are these jokes? The so-called Julian date, ordinal date or "day of year" is useful in a lot of calculations.
date +%j

returns the "day of year". "date +%Y-%j" is close (thank you, Gazl) -- but he didn't say he wanted the year.

To put this in a single variable, use command substitution:

dayofyear=`date +%j`

Here's an example:

#!/bin/bash
Christmas=`date --date="2012-12-25" +%j`
dayofyear=`date +%j`
echo "There are $(($Christmas-$dayofyear)) days until Christmas."

I hope this is what the questioner was looking for.

Wastrel

suicidaleggroll 09-03-2012 11:24 AM

Quote:

Originally Posted by Wastrel (Post 4771552)
Why are the answers to this so peculiar? Why send the questioner to the Naval Observatory or tell him to build an array...? Are these jokes? The so-called Julian date, ordinal date or "day of year" is useful in a lot of calculations.
date +%j

returns the "day of year". "date +%Y-%j" is close (thank you, Gazl) -- but he didn't say he wanted the year.

To put this in a single variable, use command substitution:

dayofyear=`date +%j`

Here's an example:

#!/bin/bash
Christmas=`date --date="2012-12-25" +%j`
dayofyear=`date +%j`
echo "There are $(($Christmas-$dayofyear)) days until Christmas."

I hope this is what the questioner was looking for.

Wastrel

1 - This thread is 4 years old
2 - That's not julian day, that's day of year. http://en.wikipedia.org/wiki/Julian_day. I work with astronomers and scientists daily. If I ever referred to day of year as "julian day", I would get slapped.

Day of year is a useful date format, but it should never be confused with julian day/date.

If the OP really wanted julian day, it would probably be easiest to use "date +%s", divide by 86400, and add an offset to move 0 from 1970 AD to 4713 BC. However, I'm not sure if Unix epoch time accounts for leap seconds, so they might have to be included as well.

Wastrel 09-03-2012 05:00 PM

I stand corrected, of course. I thought the OP might have meant "day of year", and I knew it wasn't the same as Julian (although it is given the +%j "for Julian" format code by the date program.) You may be aware that some people call day-of-year the "Julian date." I was, of course, merely trying to be helpful. I'm sure after 4 years the OP has moved on by now, probably to Windows after getting the answers he got here.

I think the solution you give for computing the real Julian will work but it seems a little cumbersome. It might be easier to store the number of seconds from 4713 BC to The Epoch as an environment variable, add it, and then divide by 86400...but then what about dates before 1970? Had I not wanted to play with numbers, I would have looked it up and suggested jday(1) (http://linux.die.net/man/1/jday). Thanks for replying and for the further amusement.


All times are GMT -5. The time now is 12:16 PM.