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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Display file date as a 3 digit day

Reply to Message Icon

Name: richaja
Date: December 3, 2004 at 12:27:06 Pacific
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



Sponsored Link
Ads by Google

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

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

date +%j


0

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

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


0

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

Joe:

This thread might help you out:

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



0

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

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.


0

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

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



0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






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


Sponsored links

Ads by Google


Results for: Display file date as a 3 digit day

Passing date as a parameter www.computing.net/answers/unix/passing-date-as-a-parameter-/3667.html

Count files by date in a directory www.computing.net/answers/unix/count-files-by-date-in-a-directory/8484.html

Comparing time/date of a file... www.computing.net/answers/unix/comparing-timedate-of-a-file/3711.html