Scripts

Datum naar dagnaam

Ik heb deze functie laatst gemaakt en vond het leuk om deze hier ook maar te posten :) Deze functie genereert uit een NL-datestamp of een Internationale datestamp de volledige Nederlandse naam van de dag van deze betreffende dag. Handig en makkelijk te bewerken voor vele doeleinden

datum-naar-dagnaam
[code]
<?php
function date_to_day ($date, $inputformat) {
	########################################################
 	# syntax: date_to_day($datestamp,["NL"|"INT"]) #########
 	# NL: DD-MM-YYYY #######################################
 	# INT: YYYY-MM-DD ######################################
 	# Made for Dutch and International Datestamps only! ####
 	# OUtput produces the full dutch dayname ###############
	########################################################
	# Made by Wouter van der Burg -- February 2008 #########
	########################################################	
	########################################################	
	##
	## check if there is a timestamp in the datevar
	if (strstr($date,":")) {
		echo "<script>alert('Invalid dateformat! Only NL and US datestamps allowed, without timestamps!')</script>";
	}
	## Split up the date in its three elements
	$date_split = explode("-",$date);
	##
	## Check the inputformat to set up the dayname
	if (trim($inputformat) == "NL") {
		$day = $date_split[0];
		$month = $date_split[1]; 
		$year = $date_split[2];
	} elseif (trim($inputformat) == "INT") {
		$day = $date_split[2];
		$month = $date_split[1];
		$year = $date_split[0];
	}
	## determine the dayname (0-6 , 0= sunday and 6 = saturday)
	$day = date("w",mktime(0,0,0,$month,$day,$year));
	## Compare the output with the values in the array and return the translation
	$days[0] = "zondag";
	$days[1] = "maandag";
	$days[2] = "dinsdag";
	$days[3] = "woensdag";
	$days[4] = "donderdag";
	$days[5] = "vrijdag";
	$days[6] = "zaterdag";	
		
	return $days[$day];
		
}

echo date_to_day(date('d-m-Y'),"NL");
?>
[/code]

Reacties

0
Nog geen reacties.