note 39785 added to function.date

From: Date: Tue, 10 Feb 2004 15:52:48 +0000
Subject: note 39785 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-64963@lists.php.net to get a copy of this message
I tried looking for something to get the day name of a string in date format for an event that was coming up, ie, 13/11/04 - what day would that be? Couldn't find one, and as necessity is the mother of invention, this simple, but effective little function followed. <? function DateCalc($eventdate, $format) { //extract $eventdate to array by day/month/year ereg("([0-9]{2})/([0-9]{2})/([0-9]{4})", $eventdate, $alpha); //today's date sent to timestamp $now = strtotime(date("m/d")); //convert date entered to timestamp $then = strtotime(date("m/d", mktime(0, 0, 0, $alpha['2'], $alpha['1']))); //subtract date entered from today's date $difference = $then - $now; //add the difference to today's date $last = $difference + $now; //return final timestamp to string by $format according to strftime requirements $day = strftime($format, $last); return $day; } ?> Of course, this function assumes that the user will enter their date in date("d/m/Y") format, but for my work, it'll do fine. It would be easy enough to change at will. And I'm sure that anyone of you will be able to do a more efficient job at this - go ahead. It would make my day (no pun intended)! ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39785 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39785&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39785&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64963) next »