strtotime

PHP: Problem with strtotime

此生再无相见时 提交于 2019-11-29 16:28:22
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? 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 . Use DateTime::createFromFormat() if you know source format of date ('m.d.y H:i') in your example print DateTime::createFromFormat('m.d.y H:i',$date)->getTimestamp() Manual DateTime::createFromFormat DateTime::getTimestamp strtotime works with US

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

白昼怎懂夜的黑 提交于 2019-11-29 16:10:39
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'))); 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", $nextMonthStart)); works for me even in the edge case that the first day of next month is a saturday.

PHP - using date to find out daylight savings time

五迷三道 提交于 2019-11-29 07:58:33
I want to give date() a date and have it return if that date is DST or not. Running PHP 5.4.7 via xampp on a windows 7 box. A linux box running PHP 5.2.8 returns 0 no matter what date I give it. What's wrong with my code? echo date('I', strtotime('30-Mar-2013')); # should return a 1 but returns 0 echo date('I', strtotime('30-Mar-2013 America/Los_Angeles'))."<br>"; # returns 0 echo date('I', strtotime('31-Mar-2013 America/Los_Angeles'))."<br>"; # returns 1 The switch between DST should be between 9-Mar-2013 - 10-Mar-2013. At this point, the question is, why doesn't my PHP code return 1. You can

PHP get next occurrence of Monday from a certain date (with time)

☆樱花仙子☆ 提交于 2019-11-29 07:34:06
I'm looking for the next Thursday after a specific date, say 2014-02-25 . The problem I'm having here is that when I use the below code, the time seems to be erased. <?php $timestamp = '2014-02-25 10:30:00'; echo date('Y-m-d H:i:s', strtotime("next Thursday", strtotime($timestamp))); ?> The result I am getting is 2014-02-27 00:00:00 when I would like it to be 2014-02-27 10:30:00 Is there something I am missing here that is causing the time to be set to midnight? I appreciate the help, thanks. There is no time format that can directly express this. You need to produce a format like next

How to make strtotime parse dates in Australian (i.e. UK) format: dd/mm/yyyy?

坚强是说给别人听的谎言 提交于 2019-11-29 06:13:10
I can't beleive I've never come across this one before. Basically, I'm parsing the text in human-created text documents and one of the fields I need to parse is a date and time. Because I'm in Australia, dates are formatted like dd/mm/yyyy but strtotime only wants to parse it as a US formatted date. Also, exploding by / isn't going to work because, as I mentioned, these documents are hand-typed and some of them take the form of d M yy . I've tried multiple combinations of setlocale but no matter what I try, the language is always set to US English. I'm fairly sure setlocale is the key here,

PHP Check if current time is before specified time

怎甘沉沦 提交于 2019-11-29 06:07:52
问题 I need to check in PHP if the current time is before 2pm that day. I've done this with strtotime on dates before, however this time it's with a time only, so obviously at 0.00 each day the time will reset, and the boolean will reset from false to true . if (current_time < 2pm) { // do this } 回答1: if (date('H') < 14) { $pre2pm = true; } For more information about the date function please see the PHP manual. I have used the following time formatter: H = 24-hour format of an hour (00 to 23) 回答2:

How to get date from week number & day number and year?

﹥>﹥吖頭↗ 提交于 2019-11-29 02:41:35
问题 I'm trying to get the date from the week number, day number and year. For eg: week number = 52 day number = 4 (of week 52) year = 2013 In this case, the date should be 26-12-2013 . How can I do it using PHP? I've already tried with strtotime() , but I'm confused about the formats. Can someone help? 回答1: Make use of setISODate() <?php $gendate = new DateTime(); $gendate->setISODate(2013,52,4); //year , week num , day echo $gendate->format('d-m-Y'); //"prints" 26-12-2013 回答2: Try this code. <

php获取指定日期的前一天,前一月,前一年日期

笑着哭i 提交于 2019-11-29 01:47:13
前一天的日期为: date("Y-m-d",strtotime("-1 days",strtotime('2019-08-31'))) 前一月的日期为 date("Y-m-d",strtotime("-1 months",strtotime('2019-08-31'))) 前一年的日期为: date("Y-m-d",strtotime("-1 years",strtotime('2019-08-31'))) 后一天的日期为: date("Y-m-d",strtotime("+1 days",strtotime('2019-08-31'))) 后一月的日期为: date("Y-m-d",strtotime("+1 months",strtotime('2019-08-31'))) 后一年的日期为: date("Y-m-d",strtotime("+1 years",strtotime('2019-08-31'))) 如果不是1,就把+1或者-1换成+n或者-n就可以了。 来源: https://www.cnblogs.com/binblogs/p/11438338.html

PHP, use strtotime to subtract minutes from a date-time variable?

旧巷老猫 提交于 2019-11-29 01:28:30
I need to subtract 45 minutes from the date-time variable in PHP. The code: $thestime = '2012-07-27 20:40'; $datetime_from = date("Y-m-d h:i",strtotime("-45 minutes",strtotime($thestime))); echo $datetime_from; returns the result 2012-07-27 07:55 . It should be 2012-07-27 19:55 , though. How do I fix this? You should do: $datetime_from = date("Y-m-d H:i", strtotime("-45 minutes", strtotime($thestime))); Having H instead of h means a 24-hour format is used, representing the hour with leading zeros: 00 through 23 . You can read more on this in the PHP date function documentation . There are also

PHP获取今日、昨日、本周、上周、本月、上月、本季、上季、今年、去年

懵懂的女人 提交于 2019-11-28 19:56:45
//今天开始 $beginToday = date('Y-m-d 00:00:00', time()); //今天结束 $endToday = date('Y-m-d 23:59:59', time()); //昨天开始 $beginYesterday = date('Y-m-d 00:00:00', strtotime(' -1 day')); //昨天结束 $endYesterday = date('Y-m-d 23:59:59', strtotime(' -1 day')); //本周开始,周一开始 $beginThisWeek = date('Y-m-d 00:00:00', strtotime('this week monday')); //本周结束,周日结束 $endThisWeek = date('Y-m-d 23:59:59', strtotime('this week sunday')); //上周开始,周一开始 $beginLastWeek = date('Y-m-d 00:00:00', strtotime('last week monday')); //上周结束,周日结束 $endLastWeek = date('Y-m-d 23:59:59', strtotime('last week sunday')); //本月开始 $beginThisMonth =