PHP date and time for timestamp (custom format)

Anyone got a function that will please strtotime()but accept the format as input?

For example, I need to convert yyyymmddto a timestamp, or perhaps yyyyddmm. Therefore, I would like to indicate the format used. Also Im on Windows , therefore, is strptime()not a parameter.

+5
source share
2 answers

The PHP 5 DateTimeclass has a createFromFormatmethod that does what you need.

However, it requires PHP 5.3, so it is not always an option (for now).

+3
source

, mktime...

// Assumes yyyy-mm-dd
function fromdate($date) {
    $d = explode("-", $date);
    return mktime(0, 0, 0, $d[1], $d[2], $d[0]);
}
-1

All Articles