LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-10-2008, 12:38 AM   #1
nanda22
Member
 
Registered: Mar 2008
Posts: 58

Rep: Reputation: 15
date in julian format


Hi

I want the current date in julian format stored into one variable.
Please help me
 
Old 09-10-2008, 01:02 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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
 
Old 09-10-2008, 01:27 AM   #3
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
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.
 
Old 09-10-2008, 01:56 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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.
 
Old 09-10-2008, 08:39 AM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 621

Rep: Reputation: 136Reputation: 136
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
 
Old 09-10-2008, 11:36 AM   #6
GazL
Senior Member
 
Registered: May 2008
Posts: 3,380

Rep: Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913
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"

 
Old 09-10-2008, 12:07 PM   #7
bibh_lnxq
Member
 
Registered: Nov 2004
Location: Leiden, Netherlands
Distribution: SuSE; Fedora;Slackware
Posts: 58

Rep: Reputation: 15
[QUOTE=pinniped;3275435]
Quote:
Originally Posted by pinniped View Post
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.
 
Old 09-03-2012, 11:18 AM   #8
Wastrel
LQ Newbie
 
Registered: Sep 2012
Location: Austin, Texas
Distribution: Ubuntu
Posts: 3

Rep: Reputation: Disabled
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

Last edited by Wastrel; 09-03-2012 at 11:20 AM. Reason: I hope this is what the questioner was looking for.
 
1 members found this post helpful.
Old 09-03-2012, 11:24 AM   #9
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,747

Rep: Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977
Quote:
Originally Posted by Wastrel View Post
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.

Last edited by suicidaleggroll; 09-03-2012 at 11:36 AM.
 
Old 09-03-2012, 05:00 PM   #10
Wastrel
LQ Newbie
 
Registered: Sep 2012
Location: Austin, Texas
Distribution: Ubuntu
Posts: 3

Rep: Reputation: Disabled
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.
 
  


Reply

Tags
date, format


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Julian date from calender date tostay2003 Programming 17 09-03-2012 05:10 PM
Date format ust Linux - Newbie 2 12-21-2007 01:39 PM
date format kalleanka LQ Suggestions & Feedback 9 11-15-2006 11:36 AM
Regarding date Format ancys Programming 4 08-10-2006 05:35 AM
Date format Mik LQ Suggestions & Feedback 8 12-05-2004 10:14 AM


All times are GMT -5. The time now is 07:25 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration