parse date field
am 14.01.2010 11:01:48 von John Taylor-Johnston
How do I parse a date field from mysql?
I was hoping this would work:
$mydata->birthday = "2007-02-13";
#What month is it?
echo date("F", $mydata->birthday);
#What year is it?
echo date("Y", $mydata->birthday);
What am I missing? All I get is December 1969. Hmmm?
I am looking at the manual:
http://ca.php.net/manual/en/function.date.php
http://ca.php.net/manual/en/function.mktime.php
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functio ns.html
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: parse date field
am 14.01.2010 11:07:02 von vikash.iitb
--001636c924b2689a9f047d1d0c9a
Content-Type: text/plain; charset=UTF-8
Use strttotime() function. This will work as intended.
$mydata->birthday = strtotime("2007-02-13");
#What month is it?
echo date("F", $mydata->birthday);
#What year is it?
echo date("Y", $mydata->birthday);
-
--
Vikash Kumar
http://vika.sh
On Thu, Jan 14, 2010 at 3:31 PM, John Taylor-Johnston <
John.Taylor-Johnston@cegepsherbrooke.qc.ca> wrote:
> How do I parse a date field from mysql?
>
> I was hoping this would work:
>
> $mydata->birthday = "2007-02-13";
> #What month is it?
> echo date("F", $mydata->birthday);
> #What year is it?
> echo date("Y", $mydata->birthday);
>
> What am I missing? All I get is December 1969. Hmmm?
>
> I am looking at the manual:
> http://ca.php.net/manual/en/function.date.php
> http://ca.php.net/manual/en/function.mktime.php
> http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functio ns.html
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--001636c924b2689a9f047d1d0c9a--
Re: parse date field
am 14.01.2010 11:10:52 von Lester Caine
John Taylor-Johnston wrote:
> How do I parse a date field from mysql?
>
> I was hoping this would work:
>
> $mydata->birthday = "2007-02-13";
This just stores a string to the variable $mydata->birthday - where did you
define $mydata->birthday as a data object?
$mydata->birthday = date("2007-02-13");
> #What month is it?
> echo date("F", $mydata->birthday);
> #What year is it?
> echo date("Y", $mydata->birthday);
>
> What am I missing? All I get is December 1969. Hmmm?
>
> I am looking at the manual:
> http://ca.php.net/manual/en/function.date.php
> http://ca.php.net/manual/en/function.mktime.php
> http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functio ns.html
--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: parse date field
am 14.01.2010 11:15:21 von John Taylor-Johnston
--------------000601080403080403020205
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Super, thanks. 5:14 a.m. - My head is fogging :p
vikash wrote:
> Use strttotime() function. This will work as intended.
>
> $mydata->birthday = strtotime("2007-02-13");
> #What month is it?
> echo date("F", $mydata->birthday);
> #What year is it?
> echo date("Y", $mydata->birthday);
>
> On Thu, Jan 14, 2010 at 3:31 PM, John Taylor-Johnston
>
> > wrote:
>
> How do I parse a date field from mysql?
>
> I was hoping this would work:
>
> $mydata->birthday = "2007-02-13";
> #What month is it?
> echo date("F", $mydata->birthday);
> #What year is it?
> echo date("Y", $mydata->birthday);
>
> What am I missing? All I get is December 1969. Hmmm?
>
> I am looking at the manual:
> http://ca.php.net/manual/en/function.date.php
> http://ca.php.net/manual/en/function.mktime.php
> http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functio ns.html
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--------------000601080403080403020205--
Re: parse date field
am 14.01.2010 11:47:59 von Michael Kjeldsen
On 01/14/2010 11:01 AM, John Taylor-Johnston wrote:
> How do I parse a date field from mysql?
>
> I was hoping this would work:
>
> $mydata->birthday = "2007-02-13";
> #What month is it?
> echo date("F", $mydata->birthday);
> #What year is it?
> echo date("Y", $mydata->birthday);
>
> What am I missing? All I get is December 1969. Hmmm?
>
> I am looking at the manual:
> http://ca.php.net/manual/en/function.date.php
> http://ca.php.net/manual/en/function.mktime.php
> http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functio ns.html
>
>
Something like:
date_default_timezone_set('Europe/Copenhagen');
$somedate = '2007-02-13';
echo date("F", strtotime($somedate));
echo "\n";
echo date("Y", strtotime($somedate));
Output:
[michael@archie ~]$ php a.php
February
2007
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php