note 39785 deleted from function.date by tomsommer

From: Date: Tue, 10 Feb 2004 16:18:55 +0000
Subject: note 39785 deleted from function.date by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64964@lists.php.net to get a copy of this message
Note Submitter: moniarde@ii.net ---- 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)!

« previous php.notes (#64964) next »