0

I am having problems converting a string into datetime format in order to store variable into a datetime-type field of a sql table

value of $timestamp: 2019-02-23T08:30:03.77

$datum2 = substr($timestamp,0,19); $datum2 = str_replace('T',' ', $datum2); echo $datum2 ."<br>"; --> 2019-02-23 08:30:03 .... echo output looks ok to me $datum2 = date_format($datum2,'Y-m-d H:i:s'); 

--> error message

Warning: date_format() expects parameter 1 to be DateTimeInterface

Thank you for any hints Stefan

2 Answers 2

1

Check below code:

$date = '2019-02-23 08:30:03'; $datum2 = date('Y-m-d H:i:s', strtotime($date)); 

You can convert string date to timestamp and later can change to date format. Hope it helps you.

Sign up to request clarification or add additional context in comments.

Comments

1

You have to use date_create function on $timestamp:

$datum2 = date_format(date_create($timestamp),'Y-m-d H:i:s'); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.