For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > July 2004 > RE: [PHP-DB] php mysql dates









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [PHP-DB] php mysql dates
Irm Jr

2004-07-28, 8:56 pm

Sure I understand Y-m-d. But won't the database cry because the Month
is in text format? (January, february....)? Thanks again. =20



Subject: Re: [PHP-DB] php mysql dates

On Wed, 28 Jul 2004 14:30:24 -0700, Irm Jr <irmjr@cart.org> wrote:
>=20
> Hi all, currently I have a form which prompts for the user to choose a


> date. The dropdown lists are stored into variables:
>=20
> $month //e.g. January, February, ...
> $day //e.g 1 - 31
> $year //e.g. 2004 (four digits)
>=20
> then combined into
>=20
> $articleDate
>=20
> How can I manipulate this variable to be in such a format that I can=20
> insert the information into a DATE column in a mySQL database.
>=20
> Dates are a bit of a mystery to me as PHP and MySQL handle them=20
> differently. Your help is appreciated.
>=20


Y-m-d

--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--
Justin Patrin

2004-07-28, 8:56 pm

On Wed, 28 Jul 2004 14:39:01 -0700, Irm Jr <irmjr@cart.org> wrote:
> Sure I understand Y-m-d. But won't the database cry because the Month
> is in text format? (January, february....)? Thanks again.
>


Whoops, I should read *all* the text of the question...

Easiest way to deal with that, IMHO, is strtotime and date.

$mysqlDate = date('Y-m-d', strtotime($month.' '.$day.', '.$year));

If you're using dates far in the past or future, though, this won't
work. Better to use a date handling class, such as:

http://pear.php.net/package/Date

> Subject: Re: [PHP-DB] php mysql dates
>
>
>
> On Wed, 28 Jul 2004 14:30:24 -0700, Irm Jr <irmjr@cart.org> wrote:
>
>
> Y-m-d
>
> --
> DB_DataObject_FormBuilder - The database at your fingertips
> http://pear.php.net/package/DB_DataObject_FormBuilder
>
> paperCrane --Justin Patrin--
>


--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com