Day of the Year – closingtags </>

Day of the Year

The most recent challenge I’ve completed was to input a date in plain english (eg. November 19th) and output what day of the year that was (day #323). This was a pretty fun challenge, and was simple enough.

	function dayofyear($date, $leap) {
		$datenum = explode(" ", date('m d', strtotime($date)));
		$months = array(31,28,31,30,31,30,31,31,30,31,30,31);
		$day = 0;
		if($leap) {
			$months[1] = 29;
		for ($i=0; $i < intval($datenum[0]) - 1; $i++) {
				$day = $day + $months[$i];
		return $day + $datenum[1];
	echo dayofyear('November 19th', false);


By Dylan Hildenbrand

Full stack web developer experienced with #PHP, #SvelteKit, #JS, #NodeJS, #Linux, and #Ansible. I love a good challenge.

profile for Dylan Hildenbrand on Stack Exchange, a network of free, community-driven Q&A sites  

Do you like these posts? Consider sponsoring me or making a donation!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.