Index: wp-includes/rewrite.php
===================================================================
--- wp-includes/rewrite.php	(revision 21789)
+++ wp-includes/rewrite.php	(working copy)
@@ -728,6 +728,14 @@
 	var $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
 
 	/**
+	 * Default date endianness
+	 *
+	 * @since 3.5.0
+	 * @access private
+	 * @var string
+	 */
+	var $default_date_endian = '%year%/%monthnum%/%day%';
+	/**
 	 * Whether permalinks are being used.
 	 *
 	 * This can be either rewrite module or permalink in the HTTP query string.
@@ -867,6 +875,33 @@
 	}
 
 	/**
+	 * Retrieve the date endian from the permalink structure
+	 *
+	 * @since 3.5.0
+	 * @access public
+	 *
+	 * @return array
+	 */	
+	function get_date_endian() {
+		// The date permalink must have year, month, and day separated by slashes.
+		$alternative_endians = array( '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%' );		
+		
+		$date_endian = '';
+
+		foreach ( $alternative_endians as $endian ) {
+			if ( false !== strpos( $this->permalink_structure, $endian ) ) {
+				$date_endian = $endian;
+				break;
+			}
+		}
+		
+		if ( empty( $date_endian ) )
+			$date_endian = $this->default_date_endian;
+		
+		return $date_endian;
+	}
+	
+	/**
 	 * Retrieve date permalink structure, with year, month, and day.
 	 *
 	 * The permalink structure for the date, if not set already depends on the
@@ -895,22 +930,6 @@
 			return false;
 		}
 
-		// The date permalink must have year, month, and day separated by slashes.
-		$endians = array('%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%');
-
-		$this->date_structure = '';
-		$date_endian = '';
-
-		foreach ( $endians as $endian ) {
-			if ( false !== strpos($this->permalink_structure, $endian) ) {
-				$date_endian= $endian;
-				break;
-			}
-		}
-
-		if ( empty($date_endian) )
-			$date_endian = '%year%/%monthnum%/%day%';
-
 		// Do not allow the date tags and %post_id% to overlap in the permalink
 		// structure. If they do, move the date tags to $front/date/.
 		$front = $this->front;
@@ -924,7 +943,7 @@
 			$tok_index++;
 		}
 
-		$this->date_structure = $front . $date_endian;
+		$this->date_structure = $front . $this->get_date_endian();
 
 		return $this->date_structure;
 	}
@@ -1255,24 +1274,46 @@
 		$front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
 		//build an array of the tags (note that said array ends up being in $tokens[0])
 		preg_match_all('/%.+?%/', $permalink_structure, $tokens);
-
 		$num_tokens = count($tokens[0]);
 
 		$index = $this->index; //probably 'index.php'
 		$feedindex = $index;
 		$trackbackindex = $index;
-		//build a list from the rewritecode and queryreplace arrays, that will look something like
-		//tagname=$matches[i] where i is the current $i
-		for ( $i = 0; $i < $num_tokens; ++$i ) {
-			if ( 0 < $i )
-				$queries[$i] = $queries[$i - 1] . '&';
-			else
-				$queries[$i] = '';
+		
+		if ( EP_DATE === $ep_mask && $this->default_date_endian !== $this->get_date_endian() ) {
+			$reformatted = array( '%year%', array( '%monthnum%', '%year%' ) );
+			switch ( $this->get_date_endian() ) {
+				case '%day%/%monthnum%/%year%':
+					$reformatted[] = array( '%day%', '%monthnum%', '%year%' );
+					break;
+				case '%monthnum%/%day%/%year%':
+					$reformatted[] = array( '%monthnum%', '%day%', '%year%' );
+					break;				
+			}
+			
+			foreach ( $reformatted as $tokens ) {
+				if ( ! is_array( $tokens ) )
+					$tokens = array( $tokens );
 
-			$query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1);
-			$queries[$i] .= $query_token;
+				$query_parts = array();
+				foreach ( $tokens as $i => $token )
+					$query_parts[] = str_replace( $this->rewritecode, $this->queryreplace, $token ) . $this->preg_index( $i + 1 );
+				
+				$queries[] = join( '&', $query_parts );
+			}
+		} else {
+			//build a list from the rewritecode and queryreplace arrays, that will look something like
+			//tagname=$matches[i] where i is the current $i
+			for ( $i = 0; $i < $num_tokens; ++$i ) {
+				if ( 0 < $i )
+					$queries[$i] = $queries[$i - 1] . '&';
+				else
+					$queries[$i] = '';
+
+				$query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1);
+				$queries[$i] .= $query_token;
+			}			
 		}
-
 		//get the structure, minus any cruft (stuff that isn't tags) at the front
 		$structure = $permalink_structure;
 		if ( $front != '/' )
@@ -1285,6 +1326,17 @@
 		$dirs = $walk_dirs ? explode('/', $structure) : array( $structure );
 		$num_dirs = count($dirs);
 
+		if (EP_DATE === $ep_mask && $this->default_date_endian !== $this->get_date_endian() ) {
+			$dirs = array( '%year%', '%monthnum%/%year%' );
+			switch ( $this->get_date_endian() ) {
+				case '%day%/%monthnum%/%year%':
+					$dirs[] = '%day%/%monthnum%/%year%';
+					break;
+				case '%monthnum%/%day%/%year%':
+					$dirs[] = '%monthnum%/%day%/%year%';
+					break;				
+			}
+		}
 		//strip slashes from the front of $front
 		$front = preg_replace('|^/+|', '', $front);
 
@@ -1292,8 +1344,13 @@
 		$post_rewrite = array();
 		$struct = $front;
 		for ( $j = 0; $j < $num_dirs; ++$j ) {
-			//get the struct for this dir, and trim slashes off the front
-			$struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above
+			if ( EP_DATE === $ep_mask && $this->default_date_endian !== $this->get_date_endian() ) {
+				$struct = $front . $dirs[$j];
+			} else {
+				//get the struct for this dir, and trim slashes off the front
+				$struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above				
+			}
+
 			$struct = ltrim($struct, '/');
 
 			//replace tags with regexes
