php - cookies: every 2 Monday (every 2 week) -


what i'm trying achieve date of next next monday, pair monday of year, example year (2014) first monday 6th jan -> (after 2 weeks)-> 20th jan.

i want launch competition every 2 weeks (every 2 monday) , want set cookie expire in first minute of 3rd monday let customer see competition popup again.

i tried find solution in web no luck, don't think it's common situation

thanks in advance

considering first contest starts @ first monday of current year (i.e. year of date you're providing function), believe following should work properly:

function get_next_contest_date($current_date) {     $current_date_obj = new datetime($current_date);      $year = $current_date_obj->format("y");     $first_day_of_year = date('d', strtotime("$year-01-01"));      $week = $current_date_obj->format("w");     $contest_week = $week;      if($first_day_of_year !== 'mon') {         $contest_week--;     }      $end_date_obj = new datetime();      if($contest_week & 1) {         $end_date_obj->setisodate($year, $week + 2);     } else {         $end_date_obj->setisodate($year, $week + 1);     }      return $end_date_obj->format('y-m-d'); } 

demo: https://ideone.com/kv74zd

note: if provide date earlier first contest's date, example 2014-01-03, return first contest's date, i.e. 2014-01-06;


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -