Reputation: 341
I have two time variables time1 and time2 both of string type and with the format (yyyy:mm:dd HH:mm:ss). I need to compare them to get if:
Any help will be really appreciated. Am learning android together with php while doing a project for my Semester
Upvotes: 1
Views: 61
Reputation: 92
Check out the documentation here for strtotime()
$str1 = "2016:4:9";
$str2 = "2016:1:1";
$time1 = strtotime($str1);
$time2 = strtotime($str2);
if ($time1 > $time2) { ...
Upvotes: 1
Reputation: 565
$date1 = new DateTime("now");
$date2 = new DateTime("tomorrow");
var_dump($date1 == $date2);
var_dump($date1 < $date2);
var_dump($date1 > $date2);
// Output
bool(false)
bool(true)
bool(false)
More...
$dateA = '2008-03-01 13:34';
$dateB = '2007-04-14 15:23';
if(strtotime($dateA) > strtotime($dateB)){
// ...
}
Upvotes: 0