Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting julian date to calendar

Status
Not open for further replies.

pjb

Programmer
May 1, 2001
148
US
Is there a way to convert julian date to calendar format? To convert calendar to julian, I have used strftime(). Now I need to go from julian to calendar.
 
Hi,

I don't know any function that convert julian to calendar.
Write your own function ...

For example this awk program convert julian date in the form 'year day_of_year' to calendar innthe form 'year-month-day'

---- jul2cal.awk ---
BEGIN {
split("31,28,31,30,31,30,31,31,30,31,30,31",DM,",");
}

function IsLeapYear(y) {
return (y % 4 == 0) && ((y % 100 != 0) || (y % 400 ==0))
}

function Jul2Cal(y,d ,m) {
DM[2] = (IsLeapYear(y) ? 29 : 28);
for (m=1; m<=12; m++) {
if (DM[m] >= d) break ;
d -= DM[m] ;
}
return sprintf(&quot;%04d-%02d-%02d&quot;,y,m,d) ;
}
{
print Jul2Cal($1, $2);
}
-------------------------
Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top