Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    getting date (01-31) using year,month,doy

    I am on the last date manipulation but I am stuck.

    I have year, month and day_of_year and I need to compile an iso format date eg 2009-11-17 currently I have got it to 2009-11-289 ( It has been a long month but that is kickin' the **** out of it )

    So can any of you please point me to where there is a conversion in one of the date modules. I have loked in Date:Parse, Date:Calc and as a panic choice; Date:Format. I can't see it or several which in combination might do it.


    here is the code so you can see what I have been up to
    Code:
       my ($first_year, $first_month, $first_day) = split /-/ , $first_date, 3;
      my ($last_year, $last_month, $last_day) = split /-/ , $last_date, 3;
      my $Dd = '30'; #number_of_days_to_display
    
    
      #First_doy
      my $start_doy = Day_of_Year( $first_year, $first_month, $first_day );
    
      #last_doy
      my $last_doy = Day_of_Year( $last_year, $last_month, $last_day );
    
      #calculate last doy from start date for $Dd days
      my $number_of_days_to_show = ( $start_doy + $Dd ); # number_of_days_to_show
    
    
      #Days In first Year
      my $days_in_first_year = Days_in_Year( $first_year, '12' );
    
      
    
      my $month;
      my $year;
      my $count=0;
    
        foreach my $day_number ($start_doy .. $last_doy) 
        {
        $count++;
    print qq( doy = $day_number :: count = $count <br /> );
    
          # work out the year and month here.
          #if day_number exceeds days_in_year reset to zero 
          if ($day_number == $days_in_first_year){
          $count=001;
          }
    
          #if day_number exceeds days_in_year use $last_year and $last_month
          if ( $day_number > $days_in_first_year ) {
            $year = $last_year;
            $month = $last_month;
          } else {
            $month = $first_month;
            $year=$first_year;
          }
        
    
          #set the date (01 - 31) from day_of_year
          
    
     print qq( $count=$count : day_number = $day_number <br /> );
    bazz
    Last edited by bazz; 11-18-2009 at 07:37 PM.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    From Date::Calc
    $doy = Day_of_Year($year,$month,$day);

    This function returns the (relative) number of the day of the given date in the given year.

    E.g., "Day_of_Year($year,1,1)" returns "1", "Day_of_Year($year,2,1)" returns "32", and "Day_of_Year($year,12,31)" returns either "365" or "366".

    The day of year is sometimes also referred to as the Julian day (or date), although it has nothing to do with the Julian calendar, the calendar which was used before the Gregorian calendar.

    In order to convert the number returned by this function back into a date, use the function "Add_Delta_Days()" (described further below), as follows:
    Code:
      $doy = Day_of_Year($year,$month,$day);
      ($year,$month,$day) = Add_Delta_Days($year,1,1, $doy - 1);

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Thanks FishMonger - belatedly. Got carried away with the answer and forgot to come back until now.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •