website promotion banner
eturnkeys
Your Ad Here
Web Programming  Home Web Programming PHP Date of the Day in PHP
rss

Date of the Day in PHP

Author: Kyscorp.com More by this author


Date of the Day in PHPOverview

This is a simple script but yet very useful, it consists on : catching the date, applying a given display style to it and finally showing it up. In this tutorial we are going to choose this display style: Day of the week | Month | Day of the Month | Year | : for instance today is Wednesday April 25 2005.

Getting Data

Within this step, we're gonna use the PHP date fonction date() that allows us to gather any sort of information about about dates. The parameters we're going to use are : 'l' for the day of the week, 'd' for the day of the month, 'm' for the month and 'Y' for the year.

$nameday=date("l");
$day=date("d");
$namemonth=date("m");
$year=date("Y");

Set it in your own language

Yes you can thanks to the following step, the day of the week given by the date function is in english by default, for this change the attribution of $nameday in the following code with the name of that given day in your language, in the following example I will make it in spanish. Moreover the month will be displayed as a number by default ( 1 for january, 2 for february...) with this tutorial we're going to display the month's name in english or in any other language ;)

Name of the day:

switch ($nameday)
{
case "Monday":
$nameday="Lunes";
break;
case "Tuesday":
$nameday="Martes";
break;
case "Wednesday":
$nameday="Miercoles";
break;
case "Thursday":
$nameday="Jueves";
break;
case "Friday":
$nameday="Viernes";
break;
case "Saturday":
$nameday="Sabado";
break;
case "Sunday":
$nameday="Domingo";
break;
}

Name of the month

switch ($namemonth)
{
case 1:
$namemonth="Enero";
break;
case 2:
$namemonth="Febrero";
break;
case 3:
$namemonth="Marzo";
break;
case 4:
$namemonth="Abril";
break;
case 5:
$namemonth="Mayo";
break;
case 6:
$namemonth="Junio";
break;
case 7:
$namemonth="Julio";
break;
case 8:
$namemonth="Agosto";
break;
case 9:
$namemonth="Septiembre";
break;
case 10:
$namemonth="Octubre";
break;
case 11:
$namemonth="Noviembre";
break;
case 12:
$namemonth="Diciembre";
break;
}

Display

Just the final step; this will show the day in Spanish you may change it back to any language you may need:

print($nameday);
print(" ");
print($namemonth);
print(" ");
print($day);
print(" ");
print($year);



Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Add comments to "Date of the Day in PHP"