Domanda

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");
È stato utile?

Soluzione

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;

Altri suggerimenti

try this

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

echo floor($days/(60*60*24));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top