如何查找当前时间戳和登录日期之间的天数 [重复]

Posted

技术标签:

【中文标题】如何查找当前时间戳和登录日期之间的天数 [重复]【英文标题】:how to find number of days between current timestamp and login date [duplicate] 【发布时间】:2012-05-12 04:49:52 【问题描述】:

可能重复:How to calculate the difference between two dates using php?How to find number of days between two dates using phpHow 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 也包括时间.. 或者有没有其他方法可以从当前日期中排除时间,即它只输入日期而不是时间

【问题讨论】:

我想我得到了错误的链接... :D 但它非常相关:) 问题是关于时间戳..在上面提到的链接中只有日期而不是时间.. 【参考方案1】:
 $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));

【讨论】:

你能接受这个答案吗:)?

以上是关于如何查找当前时间戳和登录日期之间的天数 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

如何使用javascript查找两个日期之间的天数差异

查找日期之间的天数C# [重复]

用PHP计算日期和今天之间的天数[重复]

如何找到两个日期之间的天数差异[重复]

如何查找两个日期之间的连续天数

查找日期之间的天数