1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to display weekly date between two dates?

Discussion in 'PHP' started by KingCobra, Sep 9, 2011.

  1. #1
    Dear friends,

    I need a php script/page that will take two dates (mm/dd/yyyy) value from form field and display all weekly dates between two dates.

    (You do not need to create the input form, just take the value directly in php/javascript code like bellow).

    The calculation will be for 1 year from $annualStartDate

    Suppose,
    $countType = "weekly"; // It can be (weekly, biweekly, monthly, quarterly)
    $annualStartDate = "01/01/2011";
    $annualEndDate = "12/31/2011"; // one year based on $annualStartDate
    $countStartDate = "01/14/2011";

    If $CountType = "weekly" then the output will be like bellow after pressing "Calculate" button:

    Line Date Day
    ------------------
    1 14-Jan-2011 Friday
    2 21-Jan-2011 Friday
    3 28-Jan-2011 Friday
    - - - - - - - - - - - - -
    Continue
    - - - - - - - - - - - - -
    51 30-Dec-2011 Friday

    Please see the attached image.

    weekly.jpg

    I wish you will help me like previous. thank you
     
    KingCobra, Sep 9, 2011 IP
  2. babushkyn

    babushkyn Member

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    26
    #2
    $countType = "weekly"; // It can be (weekly, biweekly, monthly, quarterly)
    $annualStartDate = "01/01/2011";
    $annualEndDate = "12/31/2011"; // one year based on $annualStartDate
    $countStartDate = "01/14/2011";
    
    
    $countInterval = array('weekly' => '+1 week', 'biweekly' => '+2 weeks', 'monthly' => '+1 month', 'quarterly' => '+3 months');
    
    $i = 1;
    $date = strtotime($countStartDate);
    do {
        echo $i .' '. date('d-M-Y l', $date) .'<br />';
    
        $date = strtotime($countInterval[$countType], $date);
    
        $i++;
    } while ( strtotime($annualEndDate) >= $date );
    PHP:
     
    babushkyn, Sep 9, 2011 IP
  3. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Dear babushkyn,

    I am speechless, what I will say!!
    YOU ARE ROCK, YOU ARE BOSS, YOU ARE AMAZING, YOU ARE ....YOU ARE .... YOU ARE ALL....
    Thank You, Thank You, Thank You
    Your quick solution is 100% ok.
    Also thanks DigitalPoint to bring you here. I am proud of you found on this forum.

    I solved this another way using strtotime and for loop. But when I got your solution I think it is better than me and professional looking.

    May I know how old are you, where you from, what do you do?

    Please take my thanks again from the core of my heart.
     
    KingCobra, Sep 9, 2011 IP