Solved

php date

Posted on 2013-01-03
3
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

751 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