LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-17-2007, 08:11 PM   #1
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Rep: Reputation: 15
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
 
Old 07-17-2007, 08:19 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Does this work for you?

Code:
date -d '2007-04-01' +'%Y %j'
(Guess what the %j means!)
 
Old 07-17-2007, 08:25 PM   #3
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
The first two results look promising.

-- Well, the idea remains.

Last edited by slakmagik; 07-17-2007 at 08:27 PM. Reason: slow to post
 
Old 08-16-2007, 08:33 AM   #4
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Original Poster
Rep: Reputation: 15
sorry removed the post... would like to do some homework prior to that.

Last edited by tostay2003; 08-16-2007 at 08:37 AM.
 
Old 08-16-2007, 08:44 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by wjevans_7d1@yahoo.co View Post
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
 
Old 08-16-2007, 08:48 AM   #6
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Original Poster
Rep: Reputation: 15
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.
 
Old 08-16-2007, 08:52 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by tostay2003 View Post
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
 
Old 08-16-2007, 08:56 AM   #8
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Original Poster
Rep: Reputation: 15
I want the same output which you are getting. the year and the number of days.
 
Old 08-16-2007, 09:06 AM   #9
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

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

Last edited by makyo; 08-16-2007 at 09:08 AM.
 
Old 08-16-2007, 09:43 AM   #10
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Original Poster
Rep: Reputation: 15
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'
 
Old 08-16-2007, 12:18 PM   #11
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by tostay2003 View Post
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?
 
Old 08-16-2007, 12:45 PM   #12
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Original Poster
Rep: Reputation: 15
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.
 
Old 08-16-2007, 01:25 PM   #13
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

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

Last edited by makyo; 08-16-2007 at 01:26 PM.
 
Old 08-16-2007, 02:56 PM   #14
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Original Poster
Rep: Reputation: 15
Need it through ksh or bash.
 
Old 08-16-2007, 03:17 PM   #15
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

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


Reply



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
how to cat a log starting FROM a date TO a date graziano1968 Linux - General 7 03-21-2007 08:49 AM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 08:43 AM
thunderbird puts time instead of date under 'date' header wabbalee Linux - Software 4 11-26-2006 04:58 AM
current date - yesterday's date newbie_adm Linux - Newbie 4 09-04-2006 03:56 PM
lastlog date does not match system date? jcmj Linux - Networking 6 10-22-2002 12:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration