Overview
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"); |
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); |
Related Articles
- Date and TimeDisplay the current data and time using a very small and common code.
- Count DownThis will let you count the number of days remaining to reach a given event : for instance days left before we reach the year 2010
- Date FunctionLearn how people use the date function in there php coding.
- Time and Date using PHPIn this tutorial we will learn how to display the day and/or time by using php. Its a very easy thing to do using php (theres only one line of code, thats right, only one!) so, lets get started.
- Last Modified, Loading Time, Preload your ImagesLast Modified, Preload your Images, Loading Time. In this tutorial you will find scripts for this topics.
- Date of the Day in PHPThis 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 May 25 20...
- Make a CalendarUsing PHPs calendar functions, make a stylish dynamic calendar showing weekends, current month and more.
- Last Modified and User's Screen Resolution DetectionAn easy and efficient way to write the date a file was last modified.
We call the function filemtime() that returns an integer (the number of seconds elapsed from Jan 1st, 1970 00:00 GMT) Anyway, to make this integer viewable by human beings, we just format it using date() function. - Relative DatesIn this tutorial I am going to teach you how to create your own relative date function.
- Displaying Date and Time using PHPType exactly like below in Notepad or any other HTML Editor and save it as date.php in your localhost.
