2014-03-01 5 views
1

오늘 MySQL 테이블에있는 가입 날짜로부터 요일 수를 계산해야합니다. 날짜 수가 필요합니다. mysql 테이블에서 오늘 날짜까지의 일수

table name : mytable 
date field name : subdate 

나는이 시도했지만 작동하지 않습니다

$today = CURDATE(); 
$subdate= ('subdate'); 
$days = (strtotime($today) - strtotime($subdate))/(60 * 60 * 24); 

해결 감사 : 내 마지막 쿼리 :

$result = mysql_query("SELECT * FROM mytable WHERE country LIKE '$country' and city LIKE '$city and (datediff(CURDATE(), age))>30"); 
+0

당신이 (NOW()) 그래서'SELECT DAY를 할 수있는 시도 -이 100 시간 전에 요청 된 mytable' –

+1

로부터 DAY (SUBDATE)의 차이를 . –

답변

5

당신은에서 일의 값을 반환하는 DATEDIFF를 사용할 수 있습니다 다른 하나의 날짜

select datediff(day1, day2); 

그래서,

select datediff(CURDATE(), subdate) from mytable; 
+1

내 문제를 해결해 주셔서 감사합니다. $ result = mysql_query ("SELECT * FROM mytable where '$ country'와 city like $ city and (datediff (CURDATE(), age)> 30"); – KNOWLEDGE

0

이 MySQL의에서

$today = CURDATE(); 
$subdate= ('subdate'); 
$days = strtotime($today) - strtotime($subdate); 

echo floor($days/(60*60*24)); 
관련 문제