strtotime

how to find number of mondays or tuesdays between two dates?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have start date and end date. I need to find out the day that is Sunday or Monday etc dependent upon user click on check box. How can I find/calculate that in PHP? 回答1: You could create a function that uses strtotime() recursively to count the number of days. Since strtotime("next monday"); works just fine. function daycount($day, $startdate, $counter) { if($startdate >= time()) { return $counter; } else { return daycount($day, strtotime("next ".$day, $startdate), ++$counter); } } echo daycount("monday", strtotime("01.01.2009"), 0);

时间戳

 ̄綄美尐妖づ 提交于 2019-12-03 01:45:21
//开始时间为上个月月出 $time = date('Y-m-01' , time()); $stime = strtotime('-1 month' , strtotime($time)); //结束时间为 当月月底 下月月初之前 $etime = strtotime("+1 month", strtotime($time)); 来源: https://www.cnblogs.com/simadongyang/p/11769851.html

PHP strtotime returns a 1970 date when date column is null

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to display $row->depositdate in dd-mm-yyyy format. If the date column in database is null the date displayed is : 01-01-1970 echo " ".date('d-m-Y', strtotime($row->depositdate))." "; If the date is null in database it should display nothing , otherwise the date in dd-mm-yyyy format should be displayed. Thanks in advance Sandeep 回答1: NULL is interpreted as 0 by strtotime, since it want to be passed an integer timestamp. A timestamp of 0 means 1-1-1970. So you'll have to check for yourself if $row->depositdate === NULL , and if so, don

Strtotime() doesn't work with dd/mm/YYYY format

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I really like the strtotime() function, but the user manual doesn't give a complete description of the supported date formats. strtotime('dd/mm/YYYY') doesn't work, it works only with mm/dd/YYYY format. If I have date in dd/mm/YYYY format, how can I convert it to YYYY-mm-dd ? I can do it by using explode() function, but I think there are better solutions. 回答1: Here is the simplified solution: $date = '25/05/2010'; $date = str_replace('/', '-', $date); echo date('Y-m-d', strtotime($date)); Result: 2010-05-25 The strtotime documentation reads:

PHP check if date between two dates

匿名 (未验证) 提交于 2019-12-03 01:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I got this code from Stackoverflow and changed it slightly to work with today's date. I want to check if today fits between two dates. But this is not working. What am I missing? $paymentDate = date ( 'd/m/Y' ); echo $paymentDate ; // echos today! $contractDateBegin = date ( 'd/m/Y' , '01/01/2001' ); $contractDateEnd = date ( 'd/m/Y' , '01/01/2015' ); if ( $paymentDate > $contractDateBegin && $paymentDate 回答1: This is the right answer for your code.. Just use strtotime() php function $paymentDate = date ( 'Y-m-d' ); $paymentDate =

php 获取时间今天-明天-昨天时间戳

拈花ヽ惹草 提交于 2019-12-02 22:46:35
php获取时间今天明天昨天时间戳的实现方法。 使用php获取时间今天明天昨天时间戳 2013-06-20 11:12 <?php echo "今天:" . date ( "Y-m-d" ). "<br>" ; echo "昨天:" . date ( "Y-m-d" , strtotime ( "-1 day" )), "<br>" ; echo "明天:" . date ( "Y-m-d" , strtotime ( "+1 day" )). "<br>" ; echo "一周后:" . date ( "Y-m-d" , strtotime ( "+1 week" )). "<br>" ; echo "一周零两天四小时两秒后:" . date ( "Y-m-d G:H:s" , strtotime ( "+1 week 2 days 4 hours 2 seconds" )). "<br>" ; echo "下个星期四:" . date ( "Y-m-d" , strtotime ( "next Thursday" )). "<br>" ; echo "上个周一:" . date ( "Y-m-d" , strtotime ( "last Monday" )). "<br>" ; echo "一个月前:" . date ( "Y-m-d" , strtotime ( "last

PHP中查询指定时间范围内的所有日期,月份,季度,年份

匿名 (未验证) 提交于 2019-12-02 22:11:45
/** * 查询指定时间范围内的所有日期,月份,季度,年份 * * @param $startDate 指定开始时间,Y-m-d格式 * @param $endDate 指定结束时间,Y-m-d格式 * @param $type 类型,day 天,month 月份,quarter 季度,year 年份 * @return array */ function getDateByInterval($startDate, $endDate, $type) { if (date('Y-m-d', strtotime($startDate)) != $startDate || date('Y-m-d', strtotime($endDate)) != $endDate) { return '日期格式不正确'; } $tempDate = $startDate; $returnData = []; $i = 0; if ($type == 'day') { // 查询所有日期 while (strtotime($tempDate) < strtotime($endDate)) { $tempDate = date('Y-m-d', strtotime('+' . $i . ' day', strtotime($startDate))); $returnData[] = $tempDate;

PHP strtotime returning false for UTC time

╄→гoц情女王★ 提交于 2019-12-02 13:18:27
My colleague and I are obtaining different results from some unit tests that use strtotime. The discrepancy originates in this line: $value = strtotime('2050-05-01T20:10:29.410Z'); on my machine, this result returns the following: int(2535048629) whereas my colleague's version returns false We are both using PHP version 5.4.14 and PHPUnit 3.724. Has anyone got any idea what is causing this discrepancy, and is there a more robust approach? Glavić This is because he is on 32-bit and you are on 64-bit machine. See what echo PHP_INT_MAX; returns on both machines. More read here . If you wish to

php - add 3 minutes to date variable

旧时模样 提交于 2019-12-02 10:06:35
问题 I want to add 3 minutes to a date/time variable I have, but I'm not sure how to do this. I made the variable from a string like this: (which is in the RFC 2822 date format btw) $date = 2011-10-18T19:56:00+0200 I converted that string into date using this command: $time = date_format(DateTime::createFromFormat("Y-m-d\TH:i:sO", $date), "G:i") Now, I'd like to add 3 minutes to that variable, but I I'm not sure how. I've used the following command in my script before, but that applies to the

How to get the date of every monday in a month for a given year

て烟熏妆下的殇ゞ 提交于 2019-12-02 06:35:57
问题 I'm trying to get the date of every Monday in a month. I previously did this for every first Monday and it worked. $date = strtotime("second monday of $month[$i] $year[j]"); But this didn't work for every monday $date = strtotime("every monday of $month [$i] $year[j]"); I'm getting the month and year from an array. 回答1: Why don't you get first monday, and do a loop adding 7 days to it until it is next year? $first = strtotime("first monday of $year[$j]"); $lastday = mktime(0, 0, 0, 12, 31,