ajgwin
May 19, 2008, 11:34am
1
I have a date that looks like this:
2008/100:18:40:47.040
I need it to look like this:
2008 04 09 18 40 47 040
I have looked at datecalc and it doesn't seem like it takes the day of year for this year (or whatever year is input) and converts it into month and day. It also has to account for leap years. Did I not see it there? Is there some easy way to convert this? Thanks.
Allyson
era
May 19, 2008, 12:11pm
2
Day number of the year is known as Julian date; there's a pointer to information about that as well in http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html
from the datecalc FAQ - Julian date thread
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:
Y=2003
DOY=101
datecalc -j $(($(datecalc -j $((Y-1)) 12 31) + DOY)) | read year month day
You can get datecalc here .
hth