1833771 Members
2148 Online
110063 Solutions
New Discussion

helo command date script

 
SOLVED
Go to solution
Jairo Campana
Trusted Contributor

helo command date script

hello, I need to obtain the number of the week for a certain date when the date is xx/xx/xxx to obtain I number of week

example : number of the week :
#date +%W

so , I want to obtain I number of week for the date example 2006/12/08

thanks
legionx
6 REPLIES 6
Peter Godron
Honored Contributor

Re: helo command date script

Hi,
get yourself

A. Clay's caljd program from
http://mirrors.develooper.com/hpux/
(right at the bottom of the page)

Pete Randall
Outstanding Contributor

Re: helo command date script

Unless it has been enhanced since the last time I looked at it, I don't believe caljd.sh (or caljd.pl) have any such option.

I was recently trying to figure out the day number of the year for specific dates and couldn't seem to find a way so I'll be interested to see what sort of answers come of this.


Pete

Pete
James R. Ferguson
Acclaimed Contributor
Solution

Re: helo command date script

Hi:

Perl makes life easy:

# perl -MDate::Calc=Week_of_Year -le '($w,$y)=Week_of_Year(2006,12,8);print $w'

...returns 49

Pass the year, month and day you want. In the above, I took 2006/12/08 to mean December 8, 2006.

Regards!

...JRF...
Hein van den Heuvel
Honored Contributor

Re: helo command date script

Jairo,

Please clarify how you define 'weeknumber'.

Is it simple the a chunk of 7 days?

An ISO week?
- weeks start on a monday
- week 1 of a given year is the one that includes the first Thursday of that year. (or, equivalently, week 1 is the week that includes 4 January.)

Google for 'week number' and you'll find many write ups. This suggests you probably want to use a package like the perl above rather then code up some shell script and get it wrong for next a leap year or whatever.

hth,
Hein.

One example:
http://www.proesite.com/timex/wkcalc.htm
Peter Godron
Honored Contributor

Re: helo command date script

Hi,
Pete, you are correct - no direct option to do this. I thought the julian day difference could be used (Too simplistic, it seems)

Jairo,
http://www.computing.net/unix/wwwboard/forum/7128.html has got a ksh script, but apparently some potential problem.

So I'd go with James's perl solution, if perl is ok.
Arturo Galbiati
Esteemed Contributor

Re: helo command date script

Hi,
I use the C program mktime on HP-UX to obtain the week number ISO-8601:
$ mktime -D 2007-12-31 -F %w
1
You can get it here:
http://fresh.t-systems-sfr.com/unix/src/privat2/mktime-2.3.tar.gz/

HTH,
Art