PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Date of the Day in PHP

Date of the Day in PHP


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);



Author's URL: Kyscorp.com
PHP is open source scripting language. It\'s widely used to develop web applications. More PHP Tutorials: Featured Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

No comments yet...
Add comments to "Date of the Day in PHP"

Captcha