2012-05-02 67 views
2

可能重複之間的天數:
How to calculate the difference between two dates using PHP?
How to find number of days between two dates using php
How to find the dates between two specified date?如何找到當前的時間戳和登錄日期

我有我的表中的三個字段

seeker 
name ....current_time.... login_date 

second field i have created through timestamp phpmyadmin 
type: timestamp 
default: current_timestamp 

當導引頭到網站註冊自己的current_time通過時間戳

third field is login_date filed. when user logins then this field is updated 

//login date 
$login_date = date("Y-m-d"); 
echo "login date"."".$login_date; 
$qry1 = "update seeker set login_date = '$login_date' where name='$uname'"; 
$res1=mysql_query($qry1,$con); 

now current_date is like 
"2012-04-10 21:58:01" 

and login_date is like 
"2012-05-02" 

我想找到這兩個日期之間的天數自動插入。我不知道如何,因爲CURRENT_DATE包括時間太長減去這些日期..或是否有任何其他的方式來排除當前最新的時間,即進入只有日期沒有時間

+0

我覺得我得到了錯誤的鏈接.. 。:D但它是非常相關的:) –

+0

問題是關於時間戳..在上面提到的鏈接只有日期不是時間.. – maham

回答

10
$login_date = strtotime(x); // change x with your login date var 
$current_date = strtotime(y); // change y with your current date var 
$datediff = $current_date - $login_date; 
$days = floor($datediff/(60*60*24)); 
+0

謝謝@Dan Barzilay – maham

+0

你能接受答案:)? –

相關問題