strtotime

strtotime

am 14.01.2010 19:14:26 von John Taylor-Johnston

Hello,

In a mysql date() field, I set the default to "0000-00-00".

Therefore, $mydata->birthday = "0000-00-00";

But when I run this next line, $then = 1969.

$then=date("Y", strtotime($mydata->birthday));

Why 1969, and not 0 or nothing?

If I echo strtotime("0000-00-00");

Nothing appears. So $then should be nothing?

What is wrong with my logic?

Thanks,
John

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: strtotime

am 14.01.2010 19:20:39 von Ashley Sheridan

--=-tk228CfemoyhwTWRl761
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Thu, 2010-01-14 at 13:14 -0500, John Taylor-Johnston wrote:

> Hello,
>
> In a mysql date() field, I set the default to "0000-00-00".
>
> Therefore, $mydata->birthday = "0000-00-00";
>
> But when I run this next line, $then = 1969.
>
> $then=date("Y", strtotime($mydata->birthday));
>
> Why 1969, and not 0 or nothing?
>
> If I echo strtotime("0000-00-00");
>
> Nothing appears. So $then should be nothing?
>
> What is wrong with my logic?
>
> Thanks,
> John
>


MySQL uses a default "0000-00-00" value for date fields generally, but
when converted into a timestamp, the string equates to a false value. In
PHP, timestamps are numerical values indicating the seconds since
Midnight of the 1st January 1969. As PHP uses loose data typing, false
is converted to a 0 (zero),and strtotime("0000-00-00") returns false. As
such, it is treated as the date when time began (for the PHP date object
at least).

There's nothing wrong with your logic, but if you want to check for
empty values, then you should use an extra if statement to check if
strtotime("0000-00-00") === false

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-tk228CfemoyhwTWRl761--

Re: strtotime

am 14.01.2010 19:25:48 von Adam Richardson

--00504502c8591e63cb047d2404c8
Content-Type: text/plain; charset=ISO-8859-1

When you set the date to "0000-00-00", you start the following sequence:


1. strtotime returns false, because "0000-00-00" isn't a date it can
parse into a timestamp.
2. date returns 1969, because it's not passed a valid timestamp and it
works from December 31, 1969 for any invalid date.


On Thu, Jan 14, 2010 at 1:14 PM, John Taylor-Johnston <
John.Taylor-Johnston@cegepsherbrooke.qc.ca> wrote:

> Hello,
>
> In a mysql date() field, I set the default to "0000-00-00".
>
> Therefore, $mydata->birthday = "0000-00-00";
>
> But when I run this next line, $then = 1969.
>
> $then=date("Y", strtotime($mydata->birthday));
>
> Why 1969, and not 0 or nothing?
>
> If I echo strtotime("0000-00-00");
>
> Nothing appears. So $then should be nothing?
>
> What is wrong with my logic?
>
> Thanks,
> John
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com

--00504502c8591e63cb047d2404c8--

Re: strtotime

am 14.01.2010 21:47:20 von Kim Madsen

Hi guys

I have a question:


Ashley Sheridan wrote on 14/01/2010 19:20:
MySQL uses a default "0000-00-00" value for date fields generally, but
when converted into a timestamp, the string equates to a false value. In
PHP, timestamps are numerical values indicating the seconds since
Midnight of the 1st January 1969. As PHP uses loose data typing, false


Adam Richardson wrote on 14/01/2010 19:25:

2. date returns 1969, because it's not passed a valid timestamp and it
works from December 31, 1969 for any invalid date.


Why is this? Unixtime starts at January 1st 1970 GMT (see for instance
http://php.net/microtime), I've never heard of the other dates you
mentioned.

My guess is the time, date or GMT is wrong for Johns setup and that's
why he get 1969 and not 1970, cause something is seting time in the past

--
Kind regards
Kim Emax - masterminds.dk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: strtotime

am 14.01.2010 21:53:43 von Adam Richardson

--000e0ce0d22e274bcd047d261597
Content-Type: text/plain; charset=ISO-8859-1

I've not read this, but if the first valid date is Jan. 1st, 1970, then
passing that date back in the case of errors would lead to ambiguity. Is it
a valid date or is it an error. Passing back the date of the day just
before (in terms of time, I think it's the second before) the first valid
date lets you easily identify an error.

Again, I didn't read this anywhere, though, and I could be wrong.

Adam

On Thu, Jan 14, 2010 at 3:47 PM, Kim Madsen wrote:

> Hi guys
>
> I have a question:
>
>
> Ashley Sheridan wrote on 14/01/2010 19:20:
>
> MySQL uses a default "0000-00-00" value for date fields generally, but
> when converted into a timestamp, the string equates to a false value. In
> PHP, timestamps are numerical values indicating the seconds since
> Midnight of the 1st January 1969. As PHP uses loose data typing, false
>

>
> Adam Richardson wrote on 14/01/2010 19:25:
>
> 2. date returns 1969, because it's not passed a valid timestamp and it
> works from December 31, 1969 for any invalid date.
>

>
> Why is this? Unixtime starts at January 1st 1970 GMT (see for instance
> http://php.net/microtime), I've never heard of the other dates you
> mentioned.
>
> My guess is the time, date or GMT is wrong for Johns setup and that's why
> he get 1969 and not 1970, cause something is seting time in the past
>
> --
> Kind regards
> Kim Emax - masterminds.dk
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com

--000e0ce0d22e274bcd047d261597--

Re: strtotime

am 14.01.2010 22:13:55 von haliphax

--0016e6d7eefa5eb710047d265d03
Content-Type: text/plain; charset=UTF-8

On Thu, Jan 14, 2010 at 2:53 PM, Adam Richardson wrote:

> I've not read this, but if the first valid date is Jan. 1st, 1970, then
> passing that date back in the case of errors would lead to ambiguity. Is
> it
> a valid date or is it an error. Passing back the date of the day just
> before (in terms of time, I think it's the second before) the first valid
> date lets you easily identify an error.
>
> Again, I didn't read this anywhere, though, and I could be wrong.
>
> Adam
>
> On Thu, Jan 14, 2010 at 3:47 PM, Kim Madsen wrote:
>
> > Hi guys
> >
> > I have a question:
> >
> >
> > Ashley Sheridan wrote on 14/01/2010 19:20:
> >
> > MySQL uses a default "0000-00-00" value for date fields generally, but
> > when converted into a timestamp, the string equates to a false value. In
> > PHP, timestamps are numerical values indicating the seconds since
> > Midnight of the 1st January 1969. As PHP uses loose data typing, false
> >

> >
> > Adam Richardson wrote on 14/01/2010 19:25:
> >
> > 2. date returns 1969, because it's not passed a valid timestamp and it
> > works from December 31, 1969 for any invalid date.
> >

> >
> > Why is this? Unixtime starts at January 1st 1970 GMT (see for instance
> > http://php.net/microtime), I've never heard of the other dates you
> > mentioned.
> >
> > My guess is the time, date or GMT is wrong for Johns setup and that's why
> > he get 1969 and not 1970, cause something is seting time in the past
>

Time zones. If I have PHP spit out a date for "0" as a string on my system,
it comes back as 18:00 on December 31st, 1969, because I am in the Central
time zone.

// Todd

--0016e6d7eefa5eb710047d265d03--

Re: strtotime

am 15.01.2010 00:02:06 von John Taylor-Johnston

--------------090501090901050206090002
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

My thanks to all!

Adam Richardson wrote:
> I've not read this, but if the first valid date is Jan. 1st, 1970,
> then passing that date back in the case of errors would lead to
> ambiguity. Is it a valid date or is it an error. Passing back the
> date of the day just before (in terms of time, I think it's the second
> before) the first valid date lets you easily identify an error.
>
> Again, I didn't read this anywhere, though, and I could be wrong.
>
> Adam
>
> On Thu, Jan 14, 2010 at 3:47 PM, Kim Madsen > @emax.dk > wrote:
>
> Hi guys
>
> I have a question:
>
>
> Ashley Sheridan wrote on 14/01/2010 19:20:
>
> MySQL uses a default "0000-00-00" value for date fields generally, but
> when converted into a timestamp, the string equates to a false
> value. In
> PHP, timestamps are numerical values indicating the seconds since
> Midnight of the 1st January 1969. As PHP uses loose data typing, false
>

>
> Adam Richardson wrote on 14/01/2010 19:25:
>
> 2. date returns 1969, because it's not passed a valid timestamp
> and it works from December 31, 1969 for any invalid date.
>

>
> Why is this? Unixtime starts at January 1st 1970 GMT (see for
> instance http://php.net/microtime), I've never heard of the other
> dates you mentioned.
>
> My guess is the time, date or GMT is wrong for Johns setup and
> that's why he get 1969 and not 1970, cause something is seting
> time in the past
>
> --
> Kind regards
> Kim Emax - masterminds.dk
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
> --
> Nephtali: PHP web framework that functions beautifully
> http://nephtaliproject.com

--------------090501090901050206090002--

RE: strtotime

am 15.01.2010 14:43:27 von Bob McConnell

There are a variety of starting points available, depending on the
environment and application. See the Computer section of
for a brief
review.

Bob McConnell

-----Original Message-----
From: haliphax [mailto:haliphax@gmail.com]=20
Sent: Thursday, January 14, 2010 4:14 PM
To: php-general@lists.php.net
Subject: Re: [PHP] strtotime

On Thu, Jan 14, 2010 at 2:53 PM, Adam Richardson
wrote:

> I've not read this, but if the first valid date is Jan. 1st, 1970,
then
> passing that date back in the case of errors would lead to ambiguity.
Is
> it
> a valid date or is it an error. Passing back the date of the day just
> before (in terms of time, I think it's the second before) the first
valid
> date lets you easily identify an error.
>
> Again, I didn't read this anywhere, though, and I could be wrong.
>
> Adam
>
> On Thu, Jan 14, 2010 at 3:47 PM, Kim Madsen wrote:
>
> > Hi guys
> >
> > I have a question:
> >
> >
> > Ashley Sheridan wrote on 14/01/2010 19:20:
> >
> > MySQL uses a default "0000-00-00" value for date fields generally,
but
> > when converted into a timestamp, the string equates to a false
value. In
> > PHP, timestamps are numerical values indicating the seconds since
> > Midnight of the 1st January 1969. As PHP uses loose data typing,
false
> >

> >
> > Adam Richardson wrote on 14/01/2010 19:25:
> >
> > 2. date returns 1969, because it's not passed a valid timestamp and
it
> > works from December 31, 1969 for any invalid date.
> >

> >
> > Why is this? Unixtime starts at January 1st 1970 GMT (see for
instance
> > http://php.net/microtime), I've never heard of the other dates you
> > mentioned.
> >
> > My guess is the time, date or GMT is wrong for Johns setup and
that's why
> > he get 1969 and not 1970, cause something is seting time in the past
>

Time zones. If I have PHP spit out a date for "0" as a string on my
system,
it comes back as 18:00 on December 31st, 1969, because I am in the
Central
time zone.

// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php