Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to convert PHP String into DateTime to use in mySQL

Posted on 2013-02-06
5
Medium Priority
?
441 Views
Last Modified: 2013-02-06
I have a string that I need to convert into a datetime. The string shows the date and time like below.

2/6/2013 11:47

I need to convert this into Y-m-d H:i:s

I have tried a couple of things with no luck so far. Wondering if anyone had a quick solution. Thanks
0
Comment
Question by:ats2012
  • 2
  • 2
5 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 38861058
<?php
error_reporting(E_ALL);

$s = '2/6/2013 11:47';
$date = strtotime($s);
echo date('d/M/Y H:i:s', $date);
?>
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 38861059
See here: http://www.php.net/manual/en/function.strtotime.php and here: http://www.php.net/manual/en/function.date.php    Please read the notes for 'strtotime' because there are some limits in what it will understand.  

$nudate = strtotime("2/6/2013 11:47");
echo date("Y-m-d H:i:s", $nudate);

Open in new window

0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 38861062
Sorry,
<?php
error_reporting(E_ALL);

$s = '2/6/2013 11:47';
$date = strtotime($s);
echo date('Y-m-d H:i:s', $date);
?>

Open in new window

0
 

Author Closing Comment

by:ats2012
ID: 38861077
Works Perfect. Thank you very much.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 38861163
Really?  That is essentially identical to my answer.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

876 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