strtotime

Repeating Events on the “nth” Weekday of Every Month

ぃ、小莉子 提交于 2019-12-18 11:59:35
问题 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

Repeating Events on the “nth” Weekday of Every Month

混江龙づ霸主 提交于 2019-12-18 11:59:34
问题 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

strtotime() considered harmful?

ε祈祈猫儿з 提交于 2019-12-18 11:53:59
问题 It seems like a lot of people struggle with date/time issues in PHP, and inevitably, many of the accepted answers tend to be "Use strtotime in this way." Is this really the best way to direct people dealing with date problems? I'm beginning to feel like strtotime is sort of a nifty trick that shouldn't necessarily be relied on for important date/time calculations, and by the nature of it taking arbitrary strings, it seems like a potential source of buggy, hard-to-predict behavior. Its

Start and end time, split into 1 hour segments

让人想犯罪 __ 提交于 2019-12-18 09:13:17
问题 I have a start and end time in a timestamp format. I want to split these into timeslots of e.g 1 hour. $t1 = strtotime('2010-05-06 12:00:00'); $t2 = strtotime('2010-05-06 18:00:00'); $timeslots = array(); while ($t1 < $t2) { $t1 = $t1 + 3600; $timeslots[] = $t1; } foreach ( $timeslots as $slot ) { echo date("Y-m-d H:i:s", $slot) . '<br/>'; } Is this the most efficient way to do it or is there a better, more versatile way to do this? Occasionally when trying it with other numbers for different

PHP Converting Integer to Date, reverse of strtotime

人盡茶涼 提交于 2019-12-18 03:05:23
问题 <?php echo strtotime("2014-01-01 00:00:01")."<hr>"; // output is 1388516401 ?> I am surprised if it can be reverse. I mean can I convert 1388516401 to 2014-01-01 00:00:01 . What I actually want to know is, what's the logic behind this conversion. How php convert date to a specific integer. 回答1: Yes you can convert it back. You can try: date("Y-m-d H:i:s", 1388516401); The logic behind this conversion from date to an integer is explained in strtotime in PHP: The function expects to be given a

Why does strtotime give different result in different timezone?

六月ゝ 毕业季﹏ 提交于 2019-12-17 20:51:37
问题 I am not sure why strtotime() in PHP returns different result in different timezone even though same date is given as parameter, does anyone know the answer? I also want to know, can I do similar task (converting a datetime to an int to do calculations easily) with another function which gives same result across different timezone? EDIT: An example: If I use strtotime('2011-09-19 00:00:00') shouldn't it just return the difference between 'January 1 1970 00:00:00' and '2011-09-19 00:00:00' in

php strtotime not working

不想你离开。 提交于 2019-12-17 20:49:57
问题 so I converted this string to timestamp using strtotime: strtotime("1 Nov, 2001"); which results into the timestamp 1320177660 but then when I tried converted 1320177660 into a normal date format again using an online timestamp converter, the year ended up being 2011 rather than 2001... what am I doing wrong? 回答1: As @Evan Mulawski's comment says, the "2001" is being interpreted as the time, not the year. Take out the comma to get PHP to interpret the "2001" as a year: <?php $ts = strtotime(

Determine If Business Is Open/Closed Based On Business Hours

旧巷老猫 提交于 2019-12-17 10:29:27
问题 My code works fine if the times are AM to PM (Ex: 11 AM - 10 PM), but if the locations hours of operation are AM to AM (Ex: 9 AM - 1 AM) it breaks. Here is my code: $datedivide = explode(" - ", $day['hours']); //$day['hours'] Example 11:00 AM - 10:00 PM $from = ''.$day['days'].' '.$datedivide[0].''; $to = ''.$day['days'].' '.$datedivide[1].''; $date = date('l g:i A'); $date = is_int($date) ? $date : strtotime($date); $from = is_int($from) ? $from : strtotime($from); $to = is_int($to) ? $to :

PHP strtotime +1 month behaviour

こ雲淡風輕ζ 提交于 2019-12-17 07:33:27
问题 I know about the unwanted behaviour of PHP's function strtotime For example, when adding a month (+1 month) to dates like: 31.01.2011 -> 03.03.2011 I know it's not officially a PHP bug , and that this solution has some arguments behind it, but at least for me, this behavior has caused a lot waste of time (in the past and present) and I personally hate it. What I found even stranger is that for example in: MySQL: DATE_ADD('2011-01-31', INTERVAL 1 MONTH) returns 2011-02-28 or C# where new

Adding 30 minutes to time formatted as H:i in PHP

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 04:28:35
问题 Having a nightmare at the moment and just can't see why it isn't working I have a value in the form H:i (ie 10:00, 13:30) etc called $time What I want to do is create two new values, $startTime which is 30 mins before $time and $endTime which is 30 mins after $time I have tried the following but just doesn't seem to want to work $startTime = date("H:i",strtotime('-30 minutes',$time)); $endTime = date("H:i",strtotime('+30 minutes',$time)); If I pass through 10:00 as $time and echo out both