0

I have an SQL database table which contains a column which holds data of datetime format. Now, after getting the values of this row, I need to convert the datettime to a readable string, but I'm unable to do this. Here's the code I'm using:

$result = mysqli_query($handle, "SELECT * FROM $dbTable WHERE id=$id");

while($curr = mysqli_fetch_array($result))
{
    // CONVERT $curr['datetimefield'] TO STRING
    // echo $strong-format-of-datetime;
}

The conversion part is what I'm stuck at. If anybody could help with this, I'd be really grateful.

Thank You.

2
  • see stackoverflow.com/questions/2215354/… it might help you with what you are looking for Commented Aug 16, 2013 at 15:05
  • DATE-TIME returns readable string, are you looking to change the order? Commented Aug 16, 2013 at 15:06

2 Answers 2

4

You can change format what you want: Y-m-d H:i:s

$date = strtotime($curr['datetimefield']);
echo date('Y-m-d H:i:s', $date);
Sign up to request clarification or add additional context in comments.

Comments

-1

Also you can convert date while SQL query: STR_TO_DATE(date,'%d.%m.%Y')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.