Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert specific string to time in PHP

I need to convert a string into date format, but it's returning a weird error. The string is this:

21 nov 2012

I used:

$time = strtotime('d M Y', $string);

PHP returned the error:

Notice:  A non well formed numeric value encountered in index.php on line 11

What am I missing here?

like image 795
Dênis Montone Avatar asked Dec 16 '22 16:12

Dênis Montone


1 Answers

You're calling the function completely wrong. Just pass it

$time = strtotime('21 nov 2012')

The 2nd argument is for passing in a timestamp that the new time is relative to. It defaults to time().

Edit: That will return a unix timestamp. If you want to then format it, pass your new timestamp to the date function.

like image 87
mpen Avatar answered Dec 28 '22 02:12

mpen