Index: wp-includes/template-functions-links.php
===================================================================
--- wp-includes/template-functions-links.php	(revision 3671)
+++ wp-includes/template-functions-links.php	(working copy)
@@ -475,10 +475,9 @@
 		$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
 		return ceil($numposts / get_option('posts_per_page'));
 	} else {
-		$posts = $wp_query->posts;
-		preg_match('#WHERE\s(.*)\sGROUP BY#siU', $wp_query->request, $matches);
-		$where = preg_replace('/( AND )?post_date >= (\'|\")(.*?)(\'|\")( AND post_date <= (\'\")(.*?)(\'\"))?/siU', '', $matches[1]);
-		$num_days = $wpdb->query("SELECT DISTINCT post_date FROM $wpdb->posts WHERE $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date)");
+		preg_match('#FROM\s(.*)\sGROUP BY#siU', $wp_query->request, $matches);
+		$fromwhere = preg_replace('/( AND )?post_date >= (\'|\")(.*?)(\'|\")( AND post_date <= (\'\")(.*?)(\'\"))?/siU', '', $matches[1]);
+		$num_days = $wpdb->query("SELECT DISTINCT post_date FROM $fromwhere GROUP BY year(post_date), month(post_date), dayofmonth(post_date)");
 		return ceil($num_days / get_option('posts_per_page'));
 	}
 }

