subtracting two date arrays, reformat date array
-
Hi,
I have a array of dates from wpdb->get results which print_r out as stdclassobj([post_date]=> 2013/7/10 00:00:00
I have another string of dates generated as a sample to subtract the above dates from and return a array of available dates (i.e. days with no posts)
so using array_diff($array2, $array1) returns a error (expects too long) which is due to the time format of $array1
Anyone know how to convert the entire array into a different format?
Or would there be a better way of showing dates with no bookings (post_dates on wp_posts table)?
thanks in advance!
global $wpdb; $fdates = $wpdb->get_results("SELECT post_date FROM wp_posts INNER JOIN wp_term_relationships ON wp_term_relationships.object_id=wp_posts.ID WHERE wp_term_relationships.term_taxonomy_id = $abcvn"); function dateArray($from, $to, $value = NULL) { $begin = new DateTime($from); $end = new DateTime($to); $interval = DateInterval::createFromDateString('1 day'); $days = new DatePeriod($begin, $interval, $end); $baseArray = array(); foreach ($days as $day) { $dateKey = $day->format("Y/m/d"); $baseArray[$dateKey] = $value; } return $baseArray; } $start = mktime(0,0,0,date("m"),date("d")-30,date("Y")); $finish = mktime(0,0,0,date("m"),date("d")+5,date("Y")); $datesArray = dateArray(date("Y/m/d", $start),date("Y/m/d", $finish),true); $availdates = array_diff(date("Y/m/d",$datesArray), date("Y/m/d", $fdates)); print_r ($availdates);
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘subtracting two date arrays, reformat date array’ is closed to new replies.