Solved

php date

Posted on 2013-01-03
3
315 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

11 Experts available now in Live!

Get 1:1 Help Now