strtotime

Finding days between 2 unix timestamps in php

大兔子大兔子 提交于 2019-11-28 19:13:59
Hay, i have a database holding events. There are 2 fields 'start' and 'end', these contain timestamps. When an admin enters these dates, they only have the ability to set the day,month,year. So we are only dealing with stamps containing days,months,years, not hours,minutes,seconds (hours,minutes and seconds are set to 0,0,0). I have an event with the start time as 1262304000 and the end time as 1262908800. These convert to Jan 1 2010 and Jan 8 2010. How would i get all the days between these timestamps? I want to be able to return Jan 2 2010 (1262390400), Jan 3 2010 (1262476800) .. all the way

Why does strtotime give different result in different timezone?

被刻印的时光 ゝ 提交于 2019-11-28 13:52:14
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 seconds ? Why timezone is an issue here? And can I get something which gives just difference without

Adding Days to a Date with PHP

别等时光非礼了梦想. 提交于 2019-11-28 12:32:59
问题 I am trying to add a certain amount of days to a set date in PHP. However, all of the code I use is not working. Here is the code I am currently experiencing problems with: echo date("2013-12-01", strtotime("+7 days")); I wanting to add 7 days to the date above. When I echo out this code, it just prints '2013-12-01'. Is there a way to do this? Thanks 回答1: For the sake of completeness, here's how you do it with DateTime(): $datetime = new DateTime("2013-12-01"); $datetime->add(new DateInterval

How to convert week number and year into unix timestamp?

喜欢而已 提交于 2019-11-28 11:52:49
I'm trying to group together dates into a week number and year, and then I want to convert that week number back into a unix timestamp. How can I go about doing this? I assume you are using ISO 8601 week numbers, and want the first day of a ISO 8601 week so that e.g. Week 1 of 2011 returns January 3 2011 . strtotime can do this out of the box using the {YYYY}W{WW} format: echo date("Y-m-d", strtotime("2011W01")); // 2011-01-03 Note that the week number needs to be two digits. Shamefully, DateTime::createFromFormat , the fancy new PHP 5 way of dealing with dates, seems unable to parse this kind

PHP: Problem with strtotime

天大地大妈咪最大 提交于 2019-11-28 11:41:55
问题 What's going on with strtotime here? $today = date('m.d.y H:i', time()); echo strtotime($today); It does not output anything... What's going on? 回答1: strtotime can only parse certain formats, not any random assortment of numbers and letters. "m.d.y H:i" is not a format strtotime can parse. You'll need to parse that manually using, for example, strptime. 回答2: Use DateTime::createFromFormat() if you know source format of date ('m.d.y H:i') in your example print DateTime::createFromFormat('m.d.y

How do I find what day the last saturday of the current month is in PHP?

我的未来我决定 提交于 2019-11-28 10:40:52
问题 This works for most months, but for example, April 2011 has 5 saturdays, so this returns 23 instead of 30. $last_saturday = date("j", strtotime('Fourth Saturday'.date('F o'))); 回答1: last saturday seems to be interpreted as "previous saturday" in some constellations. This is what works for me on PHP 5.3 on Windows 7: Jump to next month's first day, and look for last saturday. $nextMonthStart = mktime(0,0,0,date('m')+1,1,date('Y')); $last_saturday = date("d.m.Y",strtotime("previous saturday",

php check for a valid date, weird date conversions

天大地大妈咪最大 提交于 2019-11-28 09:54:59
Is there a way to check to see if a date/time is valid you would think these would be easy to check: $date = '0000-00-00'; $time = '00:00:00'; $dateTime = $date . ' ' . $time; if(strtotime($dateTime)) { // why is this valid? } what really gets me is this: echo date('Y-m-d', strtotime($date)); results in: "1999-11-30", huh? i went from 0000-00-00 to 1999-11-30 ??? I know i could do comparison to see if the date is either of those values is equal to the date i have but it isn't a very robust way to check. Is there a good way to check to see if i have a valid date? Anyone have a good function to

php获取前一小时、前一天、三天前、前一个月、三个月前、前一年的时间

陌路散爱 提交于 2019-11-28 09:36:43
1 //php获取前一个小时的时间: 2 3 $mtime= date("Y-m-d H:i:s", strtotime("-1 hour")); 4 //php获取前一天的时间: 5 6 $mtime= date("Y-m-d H:i:s", strtotime("-1 day")); 7 //php获取三天前的时间: 8 9 $mtime= date("Y-m-d H:i:s", strtotime("-3 day")); 10 //php获取前一个月的时间: 11 12 $mtime= date("Y-m-d H:i:s", strtotime("-1 month")); 13 //php获取三个月前的时间: 14 15 $mtime= date("Y-m-d H:i:s", strtotime("-3 month")); 16 //php获取前一年的时间: 17 18 $mtime= date("Y-m-d H:i:s", strtotime("-1 year")); 来源: https://www.cnblogs.com/realredboy/p/10748171.html

php获取前一天,前一个月,前一年的时间

左心房为你撑大大i 提交于 2019-11-28 09:36:04
获取前一天的时间: $mytime= date("Y-m-d H:i:s", strtotime("-1 day")); 获取三天前的时间: $mytime= date("Y-m-d H:i:s", strtotime("-3 day")); 获取前一个月的时间: $mytime= date("Y-m-d H:i:s", strtotime("-1 month")); 获取前3个月的时间: $mytime= date("Y-m-d H:i:s", strtotime("-3 month")); 获取前一个小时的时间: $mytime= date("Y-m-d H:i:s", strtotime("-1 hour")); 获取前一年的时间: $mytime= date("Y-m-d H:i:s", strtotime("-1 year")); 来源: http://www.cnblogs.com/hgj123/p/4915173.html

php获取前一天,前一个月,前一年的时间

丶灬走出姿态 提交于 2019-11-28 09:35:55
获取前一天的时间: $mytime= date("Y-m-d H:i:s", strtotime("-1 day")); 获取三天前的时间: $mytime= date("Y-m-d H:i:s", strtotime("-3 day")); 获取前一个月的时间: $mytime= date("Y-m-d H:i:s", strtotime("-1 month")); 获取前3个月的时间: $mytime= date("Y-m-d H:i:s", strtotime("-3 month")); 获取前一个小时的时间: $mytime= date("Y-m-d H:i:s", strtotime("-1 hour")); 获取前一年的时间: $mytime= date("Y-m-d H:i:s", strtotime("-1 year")); 来源: http://www.cnblogs.com/yxwkf/p/5058655.html