php - Check if one datetime is higher then another datetime -
i have question , have 2 input boxes type datetime-local can see below.
from <input type="datetime-local" value="2017-01-11t08:30:00"name="datemin" step=1> till <input type="datetime-local" value="2017-01-11t08:30:00"name="datemax" step=1><input type="submit" name="daysubmit">
now want check php if the date datemax higher date datemin , if date datemin lower datemax. know how can that?
i post values of 2 inputboxes , format value "yyyy-mm-ddthh:mm:ss" "yyyy-mm-dd hh:mm:ss".
this php code have far:
if(!empty($_post["datemin"]) , !empty($_post["datemax"])) { $datemin=$_post["datemin"]; $datemin= str_replace("t"," ",$datemin); $datemax=$_post["datemax"]; $datemax= str_replace("t"," ",$datemax); //here want compare 2 datetimes }
you can use datetime objects comparable , handle daylight savings time timezones.
$date1 = new datetime('2017-01-11t08:30:00'); $date2 = new datetime('2017-01-12t08:30:00'); if ($date2 > $date1) { echo 'greater!'; } else { echo 'less!'; }
Comments
Post a Comment