note 12610 deleted from function.getdate by jimw

From: Date: Mon, 22 Oct 2001 23:42:07 +0000
Subject: note 12610 deleted from function.getdate by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-19300@lists.php.net to get a copy of this message
I have been under the false illusion that getdate() would not work with dates from before the Epoch (as it would have to deal with minus values, and there's no reference to anyone else having used minus values), until I wrote a little function to test my own pre-conceived beliefs. Getdate is so powerful; I wanted to find out the actual day one of our family members' was born and new that it would be possible with getdate(), if it accepted minus values. As an afterthought, I then thought I'd throw checkdate() in as well, just in case I decide to use this for a general web application. Anyway, enough of the babble, here's the function: /* Starting date. */ $date = date("1949-09-18"); function GetBirthday($date) { list($year, $month, $day) = explode("-", $date); if (!checkdate($month, $day, $year)) { echo "The date specified was invalid."; } else { $timestamp = mktime(0, 0, 0, $month, $day, $year); $fetch_date = getdate($timestamp); if ($fetch_date['mday'] == 1 || $fetch_date['mday'] == 21 || $fetch_date['mday'] == 31) { $date_suffix = "st"; } else if ($fetch_date['mday'] == 2 || $fetch_date['mday'] == 22) { $date_suffix = "nd"; } else if ($fetch_date['mday'] == 3 || $fetch_date['mday'] == 23) { $date_suffix = "rd"; } else { $date_suffix = "th"; } echo "A close family members' birthday was ".$fetch_date['weekday']." the ".$fetch_date['mday'].$date_suffix." ".$fetch_date['month'].", ".$fetch_date['year']; } } GetBirthday($date); ?> Hope someone can make some use of it :)

« previous php.notes (#19300) next »