?
Solved

How to convert PHP String into DateTime to use in mySQL

Posted on 2013-02-06
5
Medium Priority
?
440 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
[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
  • 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

Industry Leaders: 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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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 count occurrences of each item in an array.
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

719 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