lococobra Posted November 29, 2010 Share Posted November 29, 2010 Current time when testing was: 1291064453 I run the following: echo date('m/d/y', strtotime('first day', 1291064453)); Expecting: 11/1/10 What I actually get: 11/30/10 Can anyone explain this? Quote Link to comment Share on other sites More sharing options...
requinix Posted November 29, 2010 Share Posted November 29, 2010 Doesn't do it for me so my first suspicion is a thing with timezones. What timezone are you in? Also, what version of PHP do you have? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2010 Share Posted November 29, 2010 'first day' means '1 day' and is adding one day to the current date. Quote Link to comment Share on other sites More sharing options...
lococobra Posted November 29, 2010 Author Share Posted November 29, 2010 Ah, stupid me... Wasn't paying attention to the month.. On the php.net comments someone said that first day would get the first day of the month. Anyone have an alternative method of getting that? Quote Link to comment Share on other sites More sharing options...
jdavidbakr Posted November 29, 2010 Share Posted November 29, 2010 Maybe just echo date('m/1/y', 1291064453); Quote Link to comment Share on other sites More sharing options...
salathe Posted November 29, 2010 Share Posted November 29, 2010 strtotime() is not magic, it only understand specific input. Your "first day" is simply (quite rightly) being interpreted as a movement relative to the specified timestamp, basically "add one day". To get the first of the month, you must use "first day of" which was added to the date string parsing in PHP 5.3.0. Without that being available to you, an alternative is to use mktime() or as jdavidbakr pointed out, just fake it. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 29, 2010 Share Posted November 29, 2010 But hold on a second. If I execute (with PHP 5.3.2 on Windows) php -r "echo date('r', strtotime('first day', 1291064453));" I get Mon, 01 Nov 2010 13:00:53 -0700 Quote Link to comment Share on other sites More sharing options...
jdavidbakr Posted November 29, 2010 Share Posted November 29, 2010 But hold on a second. If I execute (with PHP 5.3.2 on Windows) php -r "echo date('r', strtotime('first day', 1291064453));" I get Mon, 01 Nov 2010 13:00:53 -0700 Must be a difference between the Windows and Linux versions of php, I get: $ php -r "echo date('r', strtotime('first day', 1291064453));" Tue, 30 Nov 2010 15:00:53 -0600 php 5.2.13 on Linux I don't know what I would expect 'first day' to return, and don't see an official list of commands in the strtotime() manual page. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 29, 2010 Share Posted November 29, 2010 Must be a difference between the Windows and Linux versions of php, I get: Could definitely be. strtotime is a Linux thing so to work on Windows the PHP devs probably had to rewrite/port it. $discrepancies++; I don't know what I would expect 'first day' to return, and don't see an official list of commands in the strtotime() manual page. Check the GNU page. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 29, 2010 Share Posted November 29, 2010 Could also be: "PHP 5.3.2" versus "php 5.2.13" Quote Link to comment Share on other sites More sharing options...
salathe Posted November 29, 2010 Share Posted November 29, 2010 But hold on a second. If I execute (with PHP 5.3.2 on Windows) php -r "echo date('r', strtotime('first day', 1291064453));" I get Mon, 01 Nov 2010 13:00:53 -0700 There are differences between PHP versions, "first day" will do as you describe for versions 5.3.0 through 5.3.2 inclusive, but not earlier or later versions (or future). The formats that strtotime and the DateTime class accept are documented here: http://php.net/datetime.formats. What formats are available when could be clarified but you get the idea. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.