简体   繁体   English

使用strtotime和datetimepicker并添加1天

[英]using strtotime with datetimepicker and adding 1 day

I'm saving to my database in the column 'time' in this format (user input using datetimepicker): 我以这种格式(用户使用datetimepicker输入)将“时间”列保存到数据库中:

dateFormat: 'mm-dd-yy',
timeFormat: 'hh:mm tt',

Example: 07-31-2014 03:37 am 示例:2014年7月31日上午03:37

I also have a column named 'status'. 我也有一个名为“状态”的列。 If the 'time' (the time saved in the column) + 24 hours surpasses the current time() then 'status' should = 'Expired'. 如果“时间”(保存在列中的时间)+ 24小时超过了当前时间(),则“状态”应为“已过期”。 Below is my attempt, but I think strtotime is not interpreting my timestamp as it's marking everything as Expired... example: 08-19-2014 02:05 am Expired 下面是我的尝试,但我认为strtotime不会解释我的时间戳,因为它会将所有内容标记为已过期...例如:2014年8月19日02:05已过期

if( (strtotime($row['time'] . "+1 days")) < time()) { $row['status'] = 'Expired'; }

Assuming you are getting date from database like in this format "07-31-2014 03:37 am". 假设您正在从数据库中获取日期,格式为“ 07-31-2014 03:37 am”。

You need to convert it and format it as strtotime readable one like below. 您需要将其转换并格式化为strtotime可读的格式,如下所示。

list($month,$day,$year,$hour,$minute) = preg_split("/[-\s:]+/", $row['time']);  

$row['time'] = $year."-".$month."-".$day." ".$hour.":".$minute.":00"; 

Try it. 试试吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM