note 99992 modified in function.strtotime by derick

From: Date: Sun, 14 Dec 2014 11:32:50 +0000
Subject: note 99992 modified in function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201161@lists.php.net to get a copy of this message
Unlike "yesterday 14:00", "14:00 yesterday" will return 00:00 of yesterday. --was-- Unlike "yesterday 14:00", "14:00 yesterday" will return 00:00 of yesterday. Here's a function that'll fix that: <?php function fix_strtotime($date) { if(preg_match('/([012]?[0-9]?:[0-5]{1}\d\s*[aA|pP]?[mM]?)(\s+)(.+)/', $date, $matches)) { return strtotime($matches[3] . $matches[2] . $matches[1]); } return strtotime($date); } echo date('Y-m-d H:i:s', fix_strtotime('14:00 yesterday')); // 2010-09-17 14:00:00 echo date('Y-m-d H:i:s', fix_strtotime('yesterday 14:00')); // 2010-09-17 14:00:00 ?> http://php.net/manual/en/function.strtotime.php

« previous php.notes (#201161) next »