strtotime

PHP strtotime incrementing by weekdays

最后都变了- 提交于 2019-11-30 19:15:20
Today is Friday, April 17, 2015. In my app, it automatically generated a "due date" for each assignment. It's set to "5 business days". To accomplish this, We use: date('m/d/Y', strtotime("+5 weekdays")); However, today, this output "04/26/2015". Why? That's a sunday. Why doesn't it give me the 24th, which is what I want? DEMO: http://codepad.org/2wvnypOC P.S. After speaking to my boss, we switched to strtotime("+5 days") , but I'm still curious what was wrong with "weekdays" . It's a bug . It has been fixed in >= 5.5.0. So you'll need to work around it or upgrade your php version. <?php

PHP - Using strtotime with a UK date format (dd-mm-yy)

送分小仙女□ 提交于 2019-11-30 17:50:08
Quite simply in PHP I have a date of 8th January 2011, in the format 08-01-11 - when I run this into strtotime and convert it back into a different date format, it reverts back to 1st August 2011 - not ideal! Is there any easy way around this, rather than having to place everything into different arrays/variables and back again? Thank you! Pekka 웃 strtotime() works with US dates only : The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp. You would have to either rearrange the date format or use date_parse_from

how to get date for holidays using php

不打扰是莪最后的温柔 提交于 2019-11-30 12:40:57
问题 For example the: 3rd Monday of January for Martin Luther King Day 3rd Monday of February for Presidents' Day (Washington's Birthday) Last Sunday of March for Easter Last Monday of May for Memorial Day I am trying to get these dates, so that I can mark it on my calendar without manually putting everything for the years to come. MODIFIED ANSWER!! $curYir = date("Y");//current year $MLK = date('Y-m-d', strtotime("january $curYir third monday")); //marthin luthor king day $PD = date('Y-m-d',

PHP strtotime() function wrong by 1 hour?

。_饼干妹妹 提交于 2019-11-30 11:36:42
I am converting dates and times into timestamps using PHP before they are inserted into my MySQL database. My problem is that when i use PHP's strtotime function the output timestamp is -1 hour behind my actual time. For example, considering todays date: 07/21/2010. When i use php code like: <?php $my_timestamp = strtotime("07/21/2010"); echo $my_timestamp; ?> The timestamp sent back is the GMT equivilent MINUS 1 hour. i.e. i get back: 20 Jul 2010 23:00:00 GMT instead of 21 Jul 2010 00:00:00 GMT. I live in the UK so my timezone is GMT. I have declared my timezone in the script using date

Check if timestamp is x hours old?

混江龙づ霸主 提交于 2019-11-30 11:31:28
Simple question, but I couldn't find any related topics that match this exact scenario. Everything I found involved MySQL or date and time rather than just time. I have a timestamp stored in a variable in the format of: 1325960262 Produced by: $newTimeStamp = time(); How can I check if this timestamp is older than 2 hours? I tried: if (strtotime($ratesTimeStamp) <= strtotime('-2 hours')) { echo "OLDER"; } else { echo "not older"; } But no luck. Drop the first strtotime ; the variable is already in timestamp form: if ($ratesTimeStamp <= strtotime('-2 hours')) { echo "OLDER"; } else { echo "not

Repeating Events on the “nth” Weekday of Every Month

拥有回忆 提交于 2019-11-30 05:21:59
I've looked at at least 2 dozen topics about this and haven't really found a good answer yet, so I come to you to ask once again for answers regarding the dreaded topic of Repeating Events. I've got Daily, Weekly, Monthly, and Yearly repeats working out fine for now (I still need to revamp the system with Exception events and whatnot, but it works for the time being). But, we want to be able to add the ability to repeat events on the (1st,2nd,3rd,4th,5th) [Sun|Mon|Tue|Wed|Thu|Fri|Sat] of every month, every other month, and every three months. Now, if I can just understand the logic for the

用strtotime()和date()函数算出2019年9月的周日日期

倾然丶 夕夏残阳落幕 提交于 2019-11-30 04:48:07
strtotime <?php $firstsunday = strtotime(date('Y-m-01')); $thisy = intval(date('m')); $diffdays=0; $count = 0; if (date('w',strtotime(date('Y-m-01')))!=0) { $diffdays=7-date('w',strtotime(date('Y-m-01'))); } else{ $count++; } $startdate =strtotime(date('Y-m-01')."+".$diffdays."day"); while (True) { if ($thisy!=intval(date('m',$startdate))) { break; } echo date('Y-m-d',$startdate)."\n"; $startdate = strtotime(date('Y-m-d',strtotime(date('Y-m-d',$startdate)."+7 day"))); // } 结果 2019-09-01 2019-09-08 2019-09-15 2019-09-22 2019-09-29 来源: https://www.cnblogs.com/saintdingspage/p/11561246.html

how to get date for holidays using php

僤鯓⒐⒋嵵緔 提交于 2019-11-30 03:18:39
For example the: 3rd Monday of January for Martin Luther King Day 3rd Monday of February for Presidents' Day (Washington's Birthday) Last Sunday of March for Easter Last Monday of May for Memorial Day I am trying to get these dates, so that I can mark it on my calendar without manually putting everything for the years to come. MODIFIED ANSWER!! $curYir = date("Y");//current year $MLK = date('Y-m-d', strtotime("january $curYir third monday")); //marthin luthor king day $PD = date('Y-m-d', strtotime("february $curYir third monday")); //presidents day $Est = date('Y-m-d', easter_date($curYir)));

PHP - Using strtotime with a UK date format (dd-mm-yy)

无人久伴 提交于 2019-11-30 01:40:41
问题 Quite simply in PHP I have a date of 8th January 2011, in the format 08-01-11 - when I run this into strtotime and convert it back into a different date format, it reverts back to 1st August 2011 - not ideal! Is there any easy way around this, rather than having to place everything into different arrays/variables and back again? Thank you! 回答1: strtotime() works with US dates only: The function expects to be given a string containing a US English date format and will try to parse that format

Check if timestamp is x hours old?

女生的网名这么多〃 提交于 2019-11-29 17:00:46
问题 Simple question, but I couldn't find any related topics that match this exact scenario. Everything I found involved MySQL or date and time rather than just time. I have a timestamp stored in a variable in the format of: 1325960262 Produced by: $newTimeStamp = time(); How can I check if this timestamp is older than 2 hours? I tried: if (strtotime($ratesTimeStamp) <= strtotime('-2 hours')) { echo "OLDER"; } else { echo "not older"; } But no luck. 回答1: Drop the first strtotime ; the variable is