Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date/time to timestamp (custom format)

Any one got a function to like strtotime() but the takes the format as input?

For example I need to convert yyyymmdd to a timestamp, or perhaps yyyyddmm. So I would like to specify the format used. Also Im on Windows so strptime() isn't an option.

like image 208
Petah Avatar asked Nov 06 '22 06:11

Petah


1 Answers

PHP 5's DateTime class has the createFromFormat method which does what you need.

However, it requires PHP 5.3 so it's not always an option (yet).

like image 189
Pekka Avatar answered Nov 09 '22 04:11

Pekka