- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Three-Digit Day of Year
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 04:50 AM
тАО09-02-2005 04:50 AM
Solved! Go to Solution.
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 04:56 AM
тАО09-02-2005 04:56 AM
Re: Three-Digit Day of Year
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 04:59 AM
тАО09-02-2005 04:59 AM
Re: Three-Digit Day of Year
I apologise - I assumed that Clay's script would handle such a thing but, going through the usage notes myself, I don't see an option for 3 digit output.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 05:05 AM
тАО09-02-2005 05:05 AM
Re: Three-Digit Day of Year
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 05:38 AM
тАО09-02-2005 05:38 AM
Solution#!/bin/ksh
#
print - n "Enter the month and day: "
read month day
set -A days 31 28 31 30 31 30 31 31 30 31 30 31
((n = 0))
((j_days = 0))
((month = month - 1))
while ((n < $month))
do
((j_days = j_days + ${days[$n]}))
((n = n + 1))
done
((j_days = j_days + $day))
echo $j_days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 05:45 AM
тАО09-02-2005 05:45 AM
Re: Three-Digit Day of Year
year=$(date +%y)
result="$j_days$year"
echo $result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 05:50 AM
тАО09-02-2005 05:50 AM
Re: Three-Digit Day of Year
In Perl:
---- julian.p ----
use Time::Local;
($y,$m,$d) = unpack "a4 a2 a2", shift @ARGV;
$s1 = timelocal(0,0,1,$d,$m-1,$y-1900);
$s2 = timelocal(0,0,0,1,0,$y-1900);
$u = 1 + ($s1 - $s2)/86400;
printf "%02d%03d\n", $y-2000, $u;
I used the $U = 1 + ... because jan-1 is day 1.
I used the hour 1 in $s1 to deal with integer truncation.
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 05:58 AM
тАО09-02-2005 05:58 AM
Re: Three-Digit Day of Year
A small perl script would easily help:
You an embed this in your shell and pass the Month Day Year as agruments. I've let it output a three-digit year and a three-digit day of year. THus 1999 outputs as 099 while 2005 appears as 105.
perl -e 'use Time::Local;$time=timelocal(0,0,0,$ARGV[1],$ARGV[0]-1,$ARGV[2]);($y,$d)=(localtime($time))[5,7];$d++;printf "%03d%03d\n"' 8 31 2005
...returns 105243
Obviously, you can use this in your shell like this:
RESULT=`perl -e `...`` $M $D $Y
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 06:17 AM
тАО09-02-2005 06:17 AM
Re: Three-Digit Day of Year
Ah yes, I forgot about the $yday = 8th field in the localtime result. Using that my script could change to:
---- cat julian.p -----
use Time::Local;
($y,$m,$d) = unpack "a4 a2 a2", shift @ARGV;
$u = 1 + (localtime(timelocal(0,0,1,$d,$m-1,$y-1900)))[7];
printf "%02d%03d\n", $y-2000, $u;
There is a minor typo / cut&paste error in the JRF solution.
Try this:
# perl -e 'use Time::Local;$time=timelocal(0,0,0,$ARGV[1],$ARGV[0]-1,$ARGV[2]);($y,$d)=(localtime($time))[5,7];$d++;printf "%03d%03d\n", $y,$d' 8 31 2005
105243
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 06:25 AM
тАО09-02-2005 06:25 AM
Re: Three-Digit Day of Year
Yes, Hein, thank you. The paste I did cut off part of the script:
#!/usr/bin/perl
use Time::Local;
$time=timelocal(0,0,0,$ARGV[1],$ARGV[0]-1,$ARGV[2]);
($y,$d) = (localtime($time)) [5,7];
$d++;
printf "%03d%03d\n",$y,$d;
I like your use of 'unpack'. It would allow Michael to pass one argument to the perl script instead of three if that suits his needs better. Thanks for the correction to mine!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 07:50 AM
тАО09-02-2005 07:50 AM
Re: Three-Digit Day of Year
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2005 07:51 AM
тАО09-02-2005 07:51 AM