philiotis has asked for the wisdom of the Perl Monks concerning the following question:

when I query unix for the day of year it gives me 330 when I do this prommatically using perl I get 329, is this because the first of jan is 0 or is there something else that's wrong? below is the code
#Returns the Zulu data type #Parameters: Number of minutes time will be offset - 0 for now sub getBinary_Zulu { my $offset = $_[0]; my $msec = 0; my $epoch_time = time(); my $offset_time = $epoch_time + ($offset * 60); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($ +offset_time); $year += 1900; print "$msec,$sec,$min,$hour,$yday,$year \n"; #debugging only return pack("I6", $msec,$sec,$min,$hour,$yday,$year); }#end getBinary_Zulu

Replies are listed 'Best First'.
Re: day of year
by fglock (Vicar) on Nov 26, 2002 at 17:04 UTC

    Sure. $yday is in the range 0..364 or 365

    If you want "zulu time" you could use gmtime instead of localtime, maybe?.

Re: day of year
by lemming (Priest) on Nov 26, 2002 at 17:07 UTC

    date +%j on a Linux box gives you the day of year starting at 1, so 1..36[56]

    localtime() gives you day of year starting at 0, so 0..36[45]

Re: day of year
by davorg (Chancellor) on Nov 26, 2002 at 20:26 UTC

    Here's a radical thought. Instead of just guessing, why not check the documentation for localtime.

    $yday is the day of the year, in the range 0..364 (or 0..365 in leap years.)

    Wasn't that simple?

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: day of year
by pg (Canon) on Nov 26, 2002 at 17:08 UTC
    And on UNIX, when you do
    date +%j
    The returned day of year for Jan. 1st is 001.
Re: day of year
by tadman (Prior) on Nov 26, 2002 at 18:07 UTC
    If you can use the date command to do it, you can always use it internally:
    use POSIX 'strftime'; print strftime("%j", localtime(time()));
    The strftime() function is able to process these percent-style variables. This may help with your remapping. Otherwise, you can always just add one.