strtotime

php函数强大的 strtotime

半城伤御伤魂 提交于 2019-12-16 18:13:17
使用strtotime可以将各种格式的时间字符串转换为时间戳 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 转换常规时间格式 echo date ( 'Y-m-d H:i:s' , strtotime ( '2016-01-30 18:00' )).PHP_EOL; echo date ( 'Y-m-d H:i:s' , strtotime ( '20160130180001' )).PHP_EOL; 转换自然时间描述 //昨天 echo date ( 'Y-m-d H:i:s' , strtotime ( 'yesterday' )).PHP_EOL; //上周 echo date ( 'Y-m-d H:i:s' , strtotime ( 'last week' )).PHP_EOL; //本周开始时间 echo date ( 'Y-m-d H:i:s' , strtotime ( 'this week midnight' )).PHP_EOL; //本月开始时间 echo date ( 'Y-m-d H:i:s' , strtotime ( 'first day of this month midnight' )).PHP_EOL; //计算相对时间 echo date ( 'Y-m-d H:i:s' , strtotime ( '+1

自定日期作为条件查询前七天日期

被刻印的时光 ゝ 提交于 2019-12-16 01:13:31
前七天 public function day($week_start) { $week_start = "201912"; $statistics = []; for ($i = 7; $i >= 0; $i--) { $statistics[] = date('d', strtotime("$week_start -$i days")); } dump($statistics);exit; return $statistics; } 前12个月 public function period($week_start) { $week_start = "201912"; $statistics = []; for ($i = 11; $i >= 0; $i--) { $statistics[] = date('Ym', strtotime("$week_start -$i month")); } dump($statistics);exit; return $statistics; } 来源: CSDN 作者: 久· 链接: https://blog.csdn.net/weixin_44944193/article/details/103465384

PHP strtotime returning false

冷暖自知 提交于 2019-12-14 03:22:40
问题 Below is the output from a database and I am trying to get the number of months between the start date and the date from the database. Below is my output string(10) "12/12/2010" Date : 12/12/2010 - 1292112000 string(10) "19/04/2000" Date : 19/04/2000 - string(10) "08/08/2007" Date : 08/08/2007 - 1186527600 string(10) "20/06/2011" Date : 20/06/2011 - As you can see, the second and fourth unix timestamps are empty. I don't know what could be causing the issue. Below is the code I'm using to

how to calculate travel time using source and destination times?

*爱你&永不变心* 提交于 2019-12-13 10:29:55
问题 Departure_Time at source is 18:25 and Arrival_Time at destination is 05:20 so tt2.Arrival_Time -tt1.Departure_Time As Travel_Time gives -130500 instead 10:55H how to achive this? any help will be appretiated..many thanks.!! edit - destination time is of second day.. 回答1: I wrote a code for you that you can modify the difference of days between departure and arrival.But but but this code is only and only for a single time zone.If you have different times in different time zones that's

Get which day of the week the month starts on for given input

爱⌒轻易说出口 提交于 2019-12-13 09:31:12
问题 I have a function which defines what day of the week the month starts on for the current month: public function firstDayOfMonth() { $day = (int) date("w", strtotime(date('m').'/01/'.date('Y').' 00:00:00')); return $day; } How would I alter the above, in a way that allows me to get the day of the week the month starts on if I give it input, for example 'June'. 回答1: public function firstDayOfMonth($month) { $day = (int) date("w", strtotime($month . ' 01,' . date('Y') . ' 00:00:00')); return

Converting a datetime back to the original format

蹲街弑〆低调 提交于 2019-12-13 08:21:57
问题 I used this code $new_date = date('Y-m-d H:i:s', timetostr($orig_date)); to convert this input Wed Jun 2 2010 to a datetime output 2010-06-02 00:00:00 When I read it from the database, how do I convert it back to the original format of Wed Jun 2 2010 ? 回答1: You can use the function strftime() (see php.net manual: strftime() for further information and all parameters) with specified parameters to convert the timestamp back to a human-readable format. You can use the function this way strftime(

strtotime() throws false on a formatted date

梦想与她 提交于 2019-12-12 22:20:50
问题 I'm having a problem with converting a formatted date string into a integer timestamp. I'm using a datepicker to input a field such as DD/MM/YY and I'm using strtotime to change it. Example usage $date_from = (!empty($_POST['datefrom'])) ? (string) $db->sql_escape($_POST['datefrom']) : false; $date_to = (!empty($_POST['dateto'])) ? (string) $db->sql_escape($_POST['dateto']) : false; $time_from = (!empty($_POST['timefrom'])) ? (string) $db->sql_escape($_POST['timefrom']) : ''; $time_to = (

How can i get last week, current week and last month record from mysql

假如想象 提交于 2019-12-12 17:10:16
问题 i am storing date in strtotime format in codeigniter. and week start from sunday. $this->db->where($this->weight . '.create_date <=', 'curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY'); $this->db->where($this->weight . '.create_date >', 'curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY'); 回答1: For taking last week: WHERE date BETWEEN date_sub(now(),INTERVAL 1 WEEK) and now(); For taking current week: WHERE YEARWEEK(`date`, 1) = YEARWEEK(CURDATE(), 1) For taking last month: year(date(FROM

Why does a unix timestamp need to be prefixed by '@' for strtotime() to understand it?

♀尐吖头ヾ 提交于 2019-12-12 10:42:17
问题 I noticed that strtotime() handles unix timestamps in an odd way, and I was curious if anyone knows why that is: var_export(strtotime('1330725042')); // false var_export(strtotime('@1330725042')); // 1330725042 Why does strtotime() return false when given a unix timestamp (unless said timestamp is prefixed by @ )? This is from the internals of a library method that I built that is intended to "resolve" an unknown-format variable into a timestamp. Using a bare strtotime() isn't helpful in this

Why does PHP date('m', strtotime('-1 months')) not work correctly for today? 07/31

眉间皱痕 提交于 2019-12-12 10:39:47
问题 I have a script that gets the current and last month in PHP like so: $currentMonth = date('m'); //Expected:07 //Result:07 $lastMonth = date('m', strtotime('-1 months')); //Expected:06 //Result:07 Today happens to be the 31 or end of the month of July. Is this result to be expected from PHP? When using -31 days the result is as expected: $lastMonth = date('m', strtotime('-31 days')); //Expected:06 //Result:06 回答1: Here's a cleaner test case that doesn't expire: <?php $origin = mktime(18, 0, 0,