2016-03-10 46 views
0

我在数据库中有一个字段,用于以时间戳格式存储用户的出生日期,现在我想添加一个搜索过滤器,其中只显示出现在两个最小或最大限制之间的出生日期的用户。例如。 minimum=20 yearsmaximum=60 years。我怎样才能比较这两个参数的时间戳日期? 我尝试了与wordpresswp_query喜欢如下:如何比较特定时间戳20到60年的时间戳?

$current = time(); 
$age_min = strtotime(date('Y')-$_REQUEST['age_min']); 
$age_max = strtotime(date('Y')-$_REQUEST['age_max']); 

//echo $age_min.'==='.$age_max; 
$age = array($age_min,$age_max); 
$bars = explode(',',$_REQUEST['bars']); 
$radius = $_REQUEST['radius']; 
$args = array('orderby' => 'registered', 
       'meta_key' => 'active', 
       'meta_value' => '1', 
       'order' => 'ASC', 
       'count_total' => true, 
       'meta_query' => array(array('key'  => 'date_of_birth', 
              'value' => $age, 
              'compare' => 'BETWEEN', 
              'type' => 'DECIMAL',),)); 
$user_query = new WP_User_Query(array($args,'exclude'=>array($user_id))); 
+0

使用的标记dbms。 (它们中的许多在执行日期/时间时不符合ANSI SQL标准。)列数据类型? – jarlh

+0

数据库是什么? – mitkosoft

+0

http://stackoverflow.com/questions/10483123/comparing-timestamp-dates-in-mysql-with-date-only-parameter –

回答

0

转换的strtotime回日期的最小值和最大值:

我已经改回年月日,你可以将其转换为您的使用DOB

$age_min = strtotime(date('Y')-$_REQUEST['age_min']); 
$age_max = strtotime(date('Y')-$_REQUEST['age_max']); 

//echo $age_min.'==='.$age_max; 
$age_min = date('Y-m-d', $age_min); 
$age_max = date('Y-m-d', $age_max); 

然后将它传递给阵列:

$age = array($age_min,$age_max);