Solved

php date

Posted on 2013-01-03
3
325 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 109

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 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