Computing.Net > Forums > Unix > Display file date as a 3 digit day

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Display file date as a 3 digit day

Reply to Message Icon

Original Message
Name: richaja
Date: December 3, 2004 at 12:27:06 Pacific
Subject: Display file date as a 3 digit day
OS: HP-UX
CPU/Ram: n/a
Comment:

Is there a way to format a date (i.e. Dec 2) to a 3 digit day of the year?

For example, I have a file with a timestamp of "Dec 2 08:42" (when I do a "ls -l"). I need a way to convert that date to it's 3 digit day of the year value (which is 337). Is there a Unix function that will do that for me?

Thanks,
Joe


Report Offensive Message For Removal


Response Number 1
Name: David Perry
Date: December 3, 2004 at 13:04:47 Pacific
Reply: (edit)

It is called a julian date. Reference your man pages to confirm this works.

date +%j


Report Offensive Follow Up For Removal

Response Number 2
Name: richaja
Date: December 3, 2004 at 13:19:28 Pacific
Reply: (edit)

date +%j
That returns today's Julian date, but I need to be able to convert the date from a file's timestamp to a Julian date. The timestamp of the file could be a date from 3 months ago.

Is there a function that I can pass a date to, that will format it to a Julian date?

Thanks,
Joe


Report Offensive Follow Up For Removal

Response Number 3
Name: nails
Date: December 4, 2004 at 15:47:39 Pacific
Reply: (edit)

Joe:

This thread might help you out:

http://www.computing.net/unix/wwwboard/forum/5223.html



Report Offensive Follow Up For Removal

Response Number 4
Name: Wolfbone
Date: December 5, 2004 at 08:35:49 Pacific
Reply: (edit)

Given a date in the form: m=Dec; y=2004; d=5, extracted from ls -l

set -A month Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Jan=31;Feb=28;Mar=31;Apr=30;May=31;Jun=30;Jul=31;Aug=31;Sep=30;Oct=31;Nov=30;Dec=31
(((y/4)*4==y))&&Feb=29;(((y/100)*100==y && (y/400)*400!=y))&&Feb=28
i=0; while [[ ${month[i]} != $m ]]; do
eval "k=\$${month[i]}"
((j+=k));((i++))
done
((j+=d));typeset -Z3 j; print $j

You just need to check for when ls -l gives the time instead of the year and replace it with the current year.


Report Offensive Follow Up For Removal

Response Number 5
Name: Wolfbone
Date: December 6, 2004 at 02:53:44 Pacific
Reply: (edit)

Hmm... Seems I was unaware of the % operator when I wrote that originally. Replace the 3rd line with:

((y%4==0))&&Feb=29;((y%100==0 && y%400!=0))&&Feb=28



Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software