Solved

How to convert PHP String into DateTime to use in mySQL

Posted on 2013-02-06
5
435 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 83

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 83

Expert Comment

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Update query with connected table data 3 38
Delete  php pages of a part of our site 8 31
How to delete values from an array using php 4 22
Ajax and PHP 9 29
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

860 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