[PHP-DB] php mysql dates
Hi all, currently I have a form which prompts for the user to choose a date. The dropdown lists are stored into variables: $month//e.g. January, February, ... $day //e.g 1 - 31 $year //e.g. 2004 (four digits) then combined into $articleDate How can I manipulate this variable to be in such a format that I can insert the information into a DATE column in a mySQL database. Dates are a bit of a mystery to me as PHP and MySQL handle them differently. Your help is appreciated. Thanks
RE: [PHP-DB] php mysql dates
Sure I understand Y-m-d. But won't the database cry because the Month is in text format? (January, february)? Thanks again. Subject: Re: [PHP-DB] php mysql dates On Wed, 28 Jul 2004 14:30:24 -0700, Irm Jr [EMAIL PROTECTED] wrote: Hi all, currently I have a form which prompts for the user to choose a date. The dropdown lists are stored into variables: $month//e.g. January, February, ... $day //e.g 1 - 31 $year //e.g. 2004 (four digits) then combined into $articleDate How can I manipulate this variable to be in such a format that I can insert the information into a DATE column in a mySQL database. Dates are a bit of a mystery to me as PHP and MySQL handle them differently. Your help is appreciated. Y-m-d -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] php mysql dates
On Wed, 28 Jul 2004 14:39:01 -0700, Irm Jr [EMAIL PROTECTED] 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 [EMAIL PROTECTED] wrote: Hi all, currently I have a form which prompts for the user to choose a date. The dropdown lists are stored into variables: $month//e.g. January, February, ... $day //e.g 1 - 31 $year //e.g. 2004 (four digits) then combined into $articleDate How can I manipulate this variable to be in such a format that I can insert the information into a DATE column in a mySQL database. Dates are a bit of a mystery to me as PHP and MySQL handle them differently. Your help is appreciated. 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-- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] php mysql dates
I would suggest creating the select dropdown so that the value is actually the numeric value of the month. i.e: select name=month id=month size=1 option value=01January/option option value=02February/option . . . /select Then you can do a simple concat before adding to the database. --Nicole --- Nicole Swan Web Programming Specialist Carroll College CCIT (406)447-4310 -Original Message- From: Justin Patrin [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 28, 2004 3:44 PM To: Irm Jr Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] php mysql dates On Wed, 28 Jul 2004 14:39:01 -0700, Irm Jr [EMAIL PROTECTED] 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 [EMAIL PROTECTED] wrote: Hi all, currently I have a form which prompts for the user to choose a date. The dropdown lists are stored into variables: $month//e.g. January, February, ... $day //e.g 1 - 31 $year //e.g. 2004 (four digits) then combined into $articleDate How can I manipulate this variable to be in such a format that I can insert the information into a DATE column in a mySQL database. Dates are a bit of a mystery to me as PHP and MySQL handle them differently. Your help is appreciated. 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-- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] php mysql dates
Thanks for the replies. I believe I have two solutions now! Take care. Much apprecitated. -Original Message- From: Swan, Nicole [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 28, 2004 2:48 PM To: [EMAIL PROTECTED] Subject: RE: [PHP-DB] php mysql dates I would suggest creating the select dropdown so that the value is actually the numeric value of the month. i.e: select name=month id=month size=1 option value=01January/option option value=02February/option . . . /select Then you can do a simple concat before adding to the database. --Nicole --- Nicole Swan Web Programming Specialist Carroll College CCIT (406)447-4310 -Original Message- From: Justin Patrin [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 28, 2004 3:44 PM To: Irm Jr Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] php mysql dates On Wed, 28 Jul 2004 14:39:01 -0700, Irm Jr [EMAIL PROTECTED] 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 [EMAIL PROTECTED] wrote: Hi all, currently I have a form which prompts for the user to choose a date. The dropdown lists are stored into variables: $month//e.g. January, February, ... $day //e.g 1 - 31 $year //e.g. 2004 (four digits) then combined into $articleDate How can I manipulate this variable to be in such a format that I can insert the information into a DATE column in a mySQL database. Dates are a bit of a mystery to me as PHP and MySQL handle them differently. Your help is appreciated. 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-- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] php mysql dates
Dear Irm Jr, Here are two functions:: http::/www.php.net/strtotime http::/www.php.net/mktime using these functions togethor you can do the need full. BTW why not store just unix time stamp in mysql database. Most People use a string field in mysql database to store timestamp, it simply work without any problem. zareef ahmed --- Irm Jr [EMAIL PROTECTED] wrote: Hi all, currently I have a form which prompts for the user to choose a date. The dropdown lists are stored into variables: $month//e.g. January, February, ... $day //e.g 1 - 31 $year //e.g. 2004 (four digits) then combined into $articleDate How can I manipulate this variable to be in such a format that I can insert the information into a DATE column in a mySQL database. Dates are a bit of a mystery to me as PHP and MySQL handle them differently. Your help is appreciated. Thanks = Zareef Ahmed :: A PHP Developer in Delhi(India). Homepage :: http://www.zasaifi.com __ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php