LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Julian date from calender date (https://www.linuxquestions.org/questions/programming-9/julian-date-from-calender-date-570248/)

tostay2003 07-17-2007 08:11 PM

Julian date from calender date
 
is there any simple command in ksh (not big programme) from which I can obtain julian date from calender date of format YYYY-MM-DD

wjevans_7d1@yahoo.co 07-17-2007 08:19 PM

Does this work for you?

Code:

date -d '2007-04-01' +'%Y %j'
(Guess what the %j means!)

slakmagik 07-17-2007 08:25 PM

The first two results look promising.

-- Well, the idea remains. ;)

tostay2003 08-16-2007 08:33 AM

sorry removed the post... would like to do some homework prior to that.

pixellany 08-16-2007 08:44 AM

Quote:

Originally Posted by wjevans_7d1@yahoo.co (Post 2827343)
Does this work for you?

Code:

date -d '2007-04-01' +'%Y %j'
(Guess what the %j means!)

On my system, "%j" gets you the day of the year. GNU "date" version 5.97
"man -k julian" returns nothing

tostay2003 08-16-2007 08:48 AM

The above command is wroking on linux but not on unix. I am trying to go through the manual pages for 'date' command, so far unable to get the same result on unix system.

pixellany 08-16-2007 08:52 AM

Quote:

Originally Posted by tostay2003 (Post 2860881)
The above command is wroking on linux but not on unix. I am trying to go through the manual pages for 'date' command, so far unable to get the same result on unix system.

Not on my Linux!!! (PCLOS 2007)
My output:
Code:

[mherring@localhost ~]$ date -d '2007-04-01' +'%Y %j'
2007 091


tostay2003 08-16-2007 08:56 AM

I want the same output which you are getting. the year and the number of days.

makyo 08-16-2007 09:06 AM

Hi.

The accepted and precise meanings of the term may be a sub-issue here.
Quote:

The use of Julian date to refer to the day-of-year (ordinal date) is usually considered to be incorrect, however it is widely used that way in the earth sciences and computer programming.

-- more at http://en.wikipedia.org/wiki/Julian_date
cheers, makyo

tostay2003 08-16-2007 09:43 AM

Not able to figure out how do get it on Unix system.
equivalent of following command in linux
Code:

date -d '2007-04-01' +'%Y %j'

pixellany 08-16-2007 12:18 PM

Quote:

Originally Posted by tostay2003 (Post 2860919)
Not able to figure out how do get it on Unix system.
equivalent of following command in linux
Code:

date -d '2007-04-01' +'%Y %j'

Does your Unix system have the date command at all? If so, then "man date" If not, can you do "man -k date" to see what the command is?

Google any help?

tostay2003 08-16-2007 12:45 PM

date command exists on unix server. Not able to figure out, how to convert into julian date.

Trying google as well, so far no luck, may be soon. :(

makyo 08-16-2007 01:25 PM

Hi.

There is a perl version of date at: http://search.cpan.org/src/CWEST/ppt...ate/index.html -- the perl Power Tools collection.

Running it to get what some call the Julian date produces:
Code:

% ./date.jgross "+%j"
228

Best wishes ... cheers, makyo

tostay2003 08-16-2007 02:56 PM

Need it through ksh or bash.

makyo 08-16-2007 03:17 PM

Hi.

Ah.

There is a collection of cfaj's scripts at http://members.torfree.net/chris/books/cfaj/ssr.html

In Chapter 8 he has a number of functions for date manipulation. Some appear to deal with "Julian". I have not tried them.

There are several algorithms in pseudo-code that IBM published just before Y2K. I have listed the contents below. If you really cannot find anything else, I can post the algorithms. IBM seems to have archived them -- I cannot find them on their web page http://www.software.ibm.com/year2000/tips15.html -- perhaps you would have better luck than I did -- or perhaps you can Google for them. You would need to translate those into shell scripts. I did a few in perl just to check them out.

Finally, sourceforge has a number of codes for Julian, but they appear to be the real Julian date forms.

Best wishes ... cheers, makyo
Quote:

Date Calculation Algorithms

These algorithms should be implemented using 32 bit or 9 digit
precision arithmetic in the computer language of your choice. All
division is integer division, i.e. you drop the remainder. For
example, 35 / 4 is 8; to make this clear the algorithms use the INT
function, INT(35/4). These algorithms make use of the MOD function,
the remainder after integer division.

The following algorithms are included:

* Convert from YYYY,MM,DD to YYYY,NNN and determine day-of-week
* Convert from YYYY,NNN to YYYY,MM,DD and determine day-of-week
* Convert from YYYY,NNN to Lilian (day 1=Fri Oct 15, 1582)
* Convert from Lilian to YYYY,NNN
* Convert from Lilian to day-of-week
* Convert from YYYY,MM,DD to YYYY,NNN
* Convert from YYYY,MM,DD to day-of-week

NOTE: Day 1 of the Lilian date in these algorithms is Friday, 15
October 1582.


All times are GMT -5. The time now is 03:19 AM.