Solved

How to convert PHP String into DateTime to use in mySQL

Posted on 2013-02-06
5
419 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 82

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 500 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 82

Expert Comment

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

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

759 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

19 Experts available now in Live!

Get 1:1 Help Now