将字符串转换为日期时间并与当前日期进行比较
Convert String to date Time and Compare with the Current Date
我有一个变量说 $A='2015-05-12 10:00:00'.
现在我需要将上述变量与当前日期和时间进行比较,并找出两者之间的时差。
要求仅在时差为3 hours or less.
时启用div标签
P.S: $A is a variable. How can I convert it into Date and time and then compare with the current date and time.?
目前试过的代码是
$TodaysDate=date('Y-m-d');
$A=$Date.' '.$StartTime;
$Todaysdate=date_create(date("Y-m-d ", strtotime($Todaysdate)));
$Final_Date=date_create(date("Y-m-d ", strtotime($A)));
$Diff_Date = date_diff($Todaysdate, $Final_Date);
$Total_Diff=$Diff_Date->format('%R%a');
这将给日期 difference.But 正是我需要的是 time.Any 帮助感谢的 3 小时差异。
希望对您有所帮助..
$A='2015-05-12 10:00:00';
$Todaysdate = strtotime("now");
$Final_Date= strtotime($A);
$diff=$Todaysdate-$Final_Date;
echo ($diff/3600)." hours ";
我有一个变量说 $A='2015-05-12 10:00:00'.
现在我需要将上述变量与当前日期和时间进行比较,并找出两者之间的时差。
要求仅在时差为3 hours or less.
P.S: $A is a variable. How can I convert it into Date and time and then compare with the current date and time.?
目前试过的代码是
$TodaysDate=date('Y-m-d');
$A=$Date.' '.$StartTime;
$Todaysdate=date_create(date("Y-m-d ", strtotime($Todaysdate)));
$Final_Date=date_create(date("Y-m-d ", strtotime($A)));
$Diff_Date = date_diff($Todaysdate, $Final_Date);
$Total_Diff=$Diff_Date->format('%R%a');
这将给日期 difference.But 正是我需要的是 time.Any 帮助感谢的 3 小时差异。
希望对您有所帮助..
$A='2015-05-12 10:00:00';
$Todaysdate = strtotime("now");
$Final_Date= strtotime($A);
$diff=$Todaysdate-$Final_Date;
echo ($diff/3600)." hours ";