![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| convert Julian date to calender date | srikanthus2002 | Shell Programming and Scripting | 6 | 05-08-2007 03:27 AM |
| Find julian date for given corresponding date | srikanthus2002 | Shell Programming and Scripting | 2 | 10-10-2006 06:33 PM |
| Julian Dates and the Cal command | shan2on | Shell Programming and Scripting | 0 | 06-26-2006 02:32 PM |
| Calendar date to Julian and Back | BCarlson | Shell Programming and Scripting | 4 | 05-14-2005 02:18 PM |
| Converting YYYYMMDD to Julian | dfran1972 | Shell Programming and Scripting | 5 | 04-28-2005 07:34 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Julian Date
I have a shell script which gets passed a parameter which is a combination of Year and Julian Date <YYYYj>. So April 11th, julian date is 101. So if I wanted April 11th for 2003 I would get the following value 2003101. How would I convert that in unix to be 20030411? I am using the korn shell.
|
| Forum Sponsor | ||
|
|
|
||||
|
What you're doing is more of a day-of-year thing rather than a Julian number thing. But a Julian number calculator can handle this stuff easily.
Get the Julian number for the day before Jan 1 of the year in question: datecalc -j 2002 12 31 52639 Now calculate the JD of the date you want: 52740=52639+101 Lastly, convert that to a date: datecalc -j 52740 2003 4 11 Of course, you will want to read the output of the last command into some variables, not just display them. With ksh, this is really just a one-liner: Code:
Y=2003 DOY=101 datecalc -j $(($(datecalc -j $((Y-1)) 12 31) + DOY)) | read year month day I see oombera beat me to the punch here 8) Oh well, now you have two options.. |