note 121936 deleted from function.strtotime by crell

From: Date: Thu, 30 Jun 2022 20:41:18 +0000
Subject: note 121936 deleted from function.strtotime by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218811@lists.php.net to get a copy of this message
Note Submitter: ivijan dot stefan at gmail dot com ---- In some countries I noticed that people storing in database strings like 20h or 20u what is equal to 20:00 and 21h30 or 21u30 what is equal to 21:30. strtotime() not understand that string and comparing or time modulation can be tricky. Because of that I wrote one good solution for it: <?php function bo_strtotime($string) { if(preg_match('/([0-9]+)[uh]{1}/i',$string)) { $string = preg_replace(array('/[uh]/i','/:(?![0-9]+)/'), array(':',':00'), $string); } return strtotime($string); } ?> This small function acts same like strtotime() only it accept 20u and 20h and convert into normal time, after that in normal unix timestamp.

« previous php.notes (#218811) next »