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!

Determine which year to use with julian dates

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi All,

Below is a script from CaKiwi,

If I am reading a file that is dated 20041225 with Julian date 360, which uses the current year (2005) to determine if it is a leap year("date +'%Y'" | getline yy), and then returns the wrong date format which I understand why this is being done.
My question is , Is there a way to determine if the year should be 2004 instead of 2005?

split("31 29 31 30 31 30 31 31 30 31 30 31",m)
"date +'%Y'" | getline yy
mm = 1
while (dd > m[mm]) {
dd -= m[mm] mm++
}
printf ("%4.4d/%2.2d/%2.2d\n", yy, mm, dd)
}

Many Thanks
Chris
 
I'm not sure if I fully understand your question, but if you want to get the year from the filename, replace

"date +'%Y'" | getline yy

by

yy = substr(FILENAME,1,2)

If the year is to be obtained from the creation date of the file, try something like

"ls -l" | getline
yy = $8

Hope this helps

CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top