converting date from php form for mysql db - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-12-2010, 12:37 AM   #1 (permalink)
Junior Member
 
Join Date: Sep 2010
Location: Indiana, US
Posts: 7
Send a message via Skype™ to tech7
Default converting date from php form for mysql db

I'm still pretty new to php. I'm trying to figure out how to convert a common input date, like 01/18/2011 into the mysql time, 2011/01/18.. I want the user to input their date in human syntax, then convert it and post it into database table.
I've read through so many different forum threads and tutorials. It seems like those codes either don't work or don't apply to what I'm trying to do. I can't seem to get a grasp of the code either, without it working...
Does anybody have or know where I can get insight into this?
tech7 is offline   Reply With Quote
Sponsored Links
Old 09-13-2010, 07:40 AM   #2 (permalink)
Regular User
 
Join Date: Sep 2010
Posts: 30
Default Re: converting date from php form for mysql db

There's no need to take care of the delimiter, all you need to care is the arrangement of the year,month,day only

You can insert date as a string in either 'YYYY-MM-DD' or 'YY-MM-DD' format. For example, '98-12-31', '98.12.31', '98/12/31', and '98@12@31' are equivalent.
Similarly, '2010-12-31', '2010.12.31', '2010/12/31', and '2010@12@31' are equivalent.

Refer this for more,

dev.mysql.com/doc/refman/5.1/en/datetime.html

So, I would suggest you ask the date either in preformatted format (YYYY-MM-DD)
or
create three input fields for YYYY, MM and DD separately.

Then at server side you combine them.

If you still want to go with your existing code. then use this,
PHP Code:
$date_php    '01/18/2011'//assuming MM/DD/YYYY
$date_array  explode('/'$date_php); 
$date_mysql $date_array[2].'/'.$date_array[0].'/'.$date_array[1]; 
PradeepKr is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 08:00 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting