Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

strtotime peculiarities

7 views
Skip to first unread message

Derek Turner

unread,
Oct 6, 2015, 8:59:41 AM10/6/15
to
<code>
echo date ("D j M Y H:i",strtotime("third Monday of February 14:00"))
</code>

echoes:

Mon 16 Feb 2015 00:54 (when run at 13.54 UTC+1)

so it seems to correctly identify and echo the date but is giving some
sort of relative time.

Is there a way of getting to echo the desired

Mon 16 Feb 2015 14:00?

Erwin Moller

unread,
Oct 6, 2015, 10:22:53 AM10/6/15
to
On 10/6/2015 2:59 PM, Derek Turner wrote:
> echo date ("D j M Y H:i",strtotime("third Monday of February 14:00"))

Try adding a timezone to PHP for the time, like UTC:

echo date ("D j M Y H:i",strtotime("third Monday of February 14:00 UTC"))

https://en.wikipedia.org/wiki/Coordinated_Universal_Time

You might also have a look at:
http://php.net/manual/en/function.date-default-timezone-get.php

ALso, check if the conversion worked.
If it returns false, you will end up with the (very suspect) date:
"Thu 1 Jan 1970 01:00"

When I see 1 Jan 1970, I get knowI am screwing up somewhere. ;-)

Regards,
Erwin Moller

--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens

Jerry Stuckle

unread,
Oct 6, 2015, 11:18:13 AM10/6/15
to
Derek,

This might be a duplicate of bug 66257 - see

https://bugs.php.net/bug.php?id=66257

It looks quite similar, but nothing's been done on it since last April.
Maybe a little goosing from your part could get it worked on.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

Jordan Doyle

unread,
Oct 7, 2015, 9:01:06 PM10/7/15
to
On Tue, 06 Oct 2015 16:23:00 +0200, Erwin Moller wrote:

> On 10/6/2015 2:59 PM, Derek Turner wrote:
>> echo date ("D j M Y H:i",strtotime("third Monday of February 14:00"))
>
> Try adding a timezone to PHP for the time, like UTC:
>
> echo date ("D j M Y H:i",strtotime("third Monday of February 14:00
> UTC"))
>
> https://en.wikipedia.org/wiki/Coordinated_Universal_Time
>
> You might also have a look at:
> http://php.net/manual/en/function.date-default-timezone-get.php
>
> ALso, check if the conversion worked.
> If it returns false, you will end up with the (very suspect) date:
> "Thu 1 Jan 1970 01:00"
>
> When I see 1 Jan 1970, I get knowI am screwing up somewhere. ;-)
>
> Regards,
> Erwin Moller

It might be worth adding a default timezone either in your ini file:

date.timezone=Europe/London

or at the top of your script using

date_default_timezone_set("Europe/London")

https://secure.php.net/manual/en/function.date-default-timezone-set.php

Regards,
Jordan Doyle

0 new messages