[英]comparison between two times
I am developing a website on php. 我正在用php开发一个网站。 I am submitting a time field as M:SAM or PM (EX: 10:55AM) something like this. 我正在将类似这样的时间字段提交为M:SAM或PM(EX:10:55 AM)。 I want to compare this field with current time. 我想将此字段与当前时间进行比较。 I am getting the current time by using this code. 通过使用此代码,我正在获取当前时间。
$time = date("h:i A");
$time = str_replace(' ','',$time);
But here I want to compare this current time with database result. 但是在这里,我想将此当前时间与数据库结果进行比较。
Thanks Sateesh. 谢谢Sateesh。
If you have 10:55AM
you can convert it to timestamp: 如果您有10:55AM
,可以将其转换为时间戳:
$input = '10:55PM';
$timestamp = strtotime($input);
$output = date('H:i', $timestamp);
// output is 22:55 (because of PM in my example so it's correct)
$a = DateTime::createFromFormat('h:iA', $time1);
$b = DateTime::createFromFormat('h:iA', $time2);
if ($a < $b) {
// $a before $b
}
This one expects both dates as 12:34AM
. 这个人预计两个日期都是12:34AM
。 You can change the format (separately) like you want. 您可以根据需要(分别)更改格式。 Have a look at DateTime::createFromFormat()
看看DateTime::createFromFormat()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.