What is the best way to convert a string to time in php?

547

I have a MySQL table containing date and time in one of its column as text (15/05/2018 11:05:40). I want to convert this string to DateTime format so that it can be used to fetch data based on the date in PHP.

793

Answer

Solution:

Use DateTime::createFromFormat

$date = date_create_from_format('d/m/Y H:i:s', $time);

People are also looking for solutions to the problem: php - Load Laravel View with Placeholders before SQL Query Completes

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.