Solved

php date

Posted on 2013-01-03
3
320 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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
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 …

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now