strtotime

PHP strtotime returning false for UTC time

家住魔仙堡 提交于 2019-12-09 03:58:43
问题 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? 回答1: This is because he is on 32-bit and you are on 64

php get correct date by week one of the year using strtotime

◇◆丶佛笑我妖孽 提交于 2019-12-09 03:58:24
问题 I used this code to get the 1st date, of the 1st week, of the year: echo date('Y-m-d',strtotime('2018W01')); #JAN 1 is Monday, returned 01/01 echo date('Y-m-d',strtotime('2013W01')); #JAN 1 is Tuesday, returned 12/31 echo date('Y-m-d',strtotime('2014W01')); #JAN 1 is Wednesday, returned 12/30 echo date('Y-m-d',strtotime('2015W01')); #JAN 1 is Thursday, returned 12/29 echo date('Y-m-d',strtotime('2016W01')); #JAN 1 is Friday, returned 01/04!? (shouldn't it be 12/28) echo date('Y-m-d',strtotime

PHP parse date column from excel sheet (CSV)

浪子不回头ぞ 提交于 2019-12-08 11:42:56
问题 I created CSV file having date field in format 12-08-2018. When I opened csv file in Excel sheet it displays and saves in format 12/AUG/2018 to file. When I am trying to parse it gives me wrong: <?php echo date('Y-m-d',strtotime('12/AUG/2018')); // 1969-12-31 ?> So, What could be the best way to handle parsing of date coming form excel sheet. 回答1: Use createFromFormat function $date = DateTime::createFromFormat('d/M/Y', '12/AUG/2018'); echo $date->format('Y-m-d'); // 2018-08-12 来源: https:/

Grouping dates into Months in php

99封情书 提交于 2019-12-08 10:44:16
问题 Created the make time below to display biweekly dates <?php $date1 = "07/05/2013"; $date2 = date('M j, Y', strtotime($date1 . " + 14 day")); $date3 = date('M j, Y', strtotime($date2 . " + 14 day")); $date4 = date('M j, Y', strtotime($date3 . " + 14 day")); $date5 = date('M j, Y', strtotime($date4 . " + 14 day")); $date6 = date('M j, Y', strtotime($date5 . " + 14 day")); $date7 = date('M j, Y', strtotime($date6 . " + 14 day")); $date8 = date('M j, Y', strtotime($date7 . " + 14 day")); $date9 =

PHP strtotime incorrect conversion

杀马特。学长 韩版系。学妹 提交于 2019-12-07 21:48:53
问题 I have looked in the manuals, It is probably a conversion weirdness but I cannot figure it out. I am getting a date from the user and attempting to validate it in PHP (version 4.1) (using strtotime and checking the return value). The users will be entering the date in European format (d-m-y) but when I supply this format date to strtotime it is inconsistent eg : 03-01-2011 is converted to the 3rd of July 2008 I know the manual says that a hyphen or dot separated date is interpreted as

PHP weekdays of current week, why is date() and strtotime taking next week?

做~自己de王妃 提交于 2019-12-07 11:52:44
问题 I am using the following code to get a Y-m-d format of weekdays: $monday = date('Y-m-d', strtotime('Monday')); $tuesday = date('Y-m-d', strtotime('Tuesday')); $wednesday = date('Y-m-d', strtotime('Wednesday')); $thursday = date('Y-m-d', strtotime('Thursday')); $friday = date('Y-m-d', strtotime('Friday')); Today is 2012-08-01 (week 31) the Monday value I need should be 2012-07-30. How come strtotime('Monday') makes it next monday? 回答1: Because date('Y-m-d') returns today's date i.e.., month of

Strange behavior of Date Function

爱⌒轻易说出口 提交于 2019-12-07 11:14:53
问题 I encountered with this question today on StackOverflow but didn't get answer. My question is echo date('Y-m-d',strtotime('2012-september-09')); // output - 2012-09-01 echo date('Y-m-d',strtotime('09-september-2012')); // output - 2012-09-09 Codepad I am confused that why the first format don't produce correct answer. Any Help? 回答1: From the manual: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y

`strtotime` bug when using + 1 month from January

本秂侑毒 提交于 2019-12-07 08:14:10
问题 I' m trying to make a ajax calendar with multiple tabs for a date range previously entered. But for example: I want get the next month, it prints march instead of february $start= "2013-01-31"; $current = date('n', strtotime("+1 month",$start)) //prints 3 I think thats occurs because february 2014 is 28 and add +31 like base from the start month but why? 回答1: You're trying to add one month to the date 2013-01-31 . It should give 31th Feburary 2013, but since the date doesn't exist, it moves

PHP strtotime() different results of monday this week

廉价感情. 提交于 2019-12-06 22:20:41
问题 I have a problem getting the date of monday in the current week. echo date('Y-m-d',strtotime('monday this week')); When I'm running the above code on my local machine (PHP 5.3) it outputs correctly '2011-03-07', but the same code on my server (PHP 5.2) outputs '2011-03-14' (that's monday next week). I've tried to run date('W') on both machines and I get the same result (10). Edit: Any ideas how get this work correctly? Thanks in advance. 回答1: Not that I've seen exactly this problem, but I've

PHP strtotime incorrect conversion

Deadly 提交于 2019-12-06 13:56:50
I have looked in the manuals, It is probably a conversion weirdness but I cannot figure it out. I am getting a date from the user and attempting to validate it in PHP (version 4.1) (using strtotime and checking the return value). The users will be entering the date in European format (d-m-y) but when I supply this format date to strtotime it is inconsistent eg : 03-01-2011 is converted to the 3rd of July 2008 I know the manual says that a hyphen or dot separated date is interpreted as European but it is not working here. $startDate=$_GET['start']; echo $startDate; $timestamp=strtotime(