Jump to content

date modify method


jimfog
 Share

Recommended Posts

The code you are going to see below was working fine before updating to PHP 5.4.4:

$now = new DateTime($newdate);//the code below depicts last and first day of month$fstdmonth=clone $now;$lstdmonth=clone $now;$fstdmonth->modify('first day of month');$lstdmonth->modify('last day of month');

I am trying to get the last and first day of a month.Now here is the error message I get upon running the script:

Warning: DateTime::modify(): Failed to parse time string (first day of month) at position 13 (m): The timezone could not be found in the database in C:\Apache24\htdocs\Appointments\Frontend\output_functions.php on line 47

Any ideas why this might happening?

Link to comment
Share on other sites

The key is

The timezone could not be found

Open up php.ini, find "date.timezone"and set that line to

date.timezone = Europe/Athens

Link to comment
Share on other sites

I have already done that:

date.timezone = "Europe/Athens"

Before I fixed the above I was getting many errors related to date functions in the script.Now the only errors left are the one mentioned in this topic.

Link to comment
Share on other sites

Ah. I see. Well, I tried the code, and I think I found it. I missed the part:

Failed to parse time string (first day of month) at position 13 (m)

What this message says is that the "m" (as in "month") is where interpretation collapsed. The message about the timezone suggests the word "month" was treated as a timezone for some reason.Using "this" clears this out, so:

$now = new DateTime($newdate);//the code below depicts last and first day of month$fstdmonth=clone $now;$lstdmonth=clone $now;$fstdmonth->modify('first day of this month');$lstdmonth->modify('last day of this month');

Link to comment
Share on other sites

Yes boen robot, that worked, thanks very much. Second, the code worked with a previous version of PHP I had. I wonder if the reason it does not work with PHP 5.4.4(the one I just update to) it is because maybe there were changes in the relative time formats syntax

Link to comment
Share on other sites

Maybe. But I don't remember "this" ever being an optional part of the relative time syntax, so this is probably more of a bug fix.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...