Solved

php date

Posted on 2013-01-03
3
326 Views
Last Modified: 2013-01-08
I have a textbox the date has to submitted as 2012-10-10 but I would like it to be 10/10/2012
0
Comment
Question by:beridius
3 Comments
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 250 total points
ID: 38740456
try like this,

$date = '10/10/2012';
list($month, $day, $year) = explode('/', $date);

$formatted_date = $year.'-'.$month.'-'.$day;
0
 
LVL 8

Assisted Solution

by:Barry62
Barry62 earned 250 total points
ID: 38740506
Do you mean the data needs to be stored as YYYY-mm-d and you want it to show up in the text field as mm/dd/YYYY?

If so, simply tell your users to enter it as mm/dd/yyyy and then validate that with javascript.  When the users submit the form, do this to convert it to a MySQL date (assume the field name is 'input_date':

$mysqldate = date('Y-m-d',$_POST['input_date']);

Open in new window



Then you can insert it to your table.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38742461
First, bookmark this page.  Then read it.  It tells most everything you need to know about how to handle DATETIME values in PHP and MySQL.  It is mostly equally applicable to MSSQL
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

It will be too much to absorb at on sitting, so you may want to refer back to the practical examples.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ajax and PHP 4 47
issue with DB import 1 36
What is this? I've never seen this... 2 29
How to get chosen background-color on every line? 10 18
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question