Pergunta

I need to calculate days number from subscribing date that i have in Mysql table to today, i need the number of days.

table name : mytable
date field name : subdate

I tried this but it doesn't work:

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

solved thanks : my final query :

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

Solução

You can use datediff which returns the value in days from one date to the other

select datediff(day1, day2);

So,

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

Outras dicas

try this

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

echo floor($days/(60*60*24));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top