|
|
Date and Time
PHP » Tips and Tutorials » Date and Time
A D V E R T I S E M E N T
Want free Oracle Magazine? Apply here now!
Function to convert datetimeWith this function, you can convert a mysql datetime datatype into any other format. This way, you only need to declare the function once and be able to format your dates everywhere in your document. Actual Time - Freeware/*
The Purpose of this function is to display the actual time in your time zone
if your web host has a different time from you.
In the function, the variable $timediff is the time difference in seconds
between your actual location and the location of your server or webhost.
If you are ahead of your server type in a positive integer such as 7200.
If you behind your server please enter a negative integer such as -7200.
In the first example you are 2 hours ahead of your server.
In the second example your are 2 hours behind your server.
Our Goal is to return a time like Saturday, August 15, 2004 08:55:05 PM EST.
*/
function actualtime () {
$timediff = -7200 ; // The time difference between your server and your time.
$timestamp = date('U'); // The timestamp at your server.
$timestamp = $timestamp + $timediff; // The calculated timestamp at your actual location.
$weekday = date('l', $timestamp); // Day of the week like Saturday.
$month = date('F', $timestamp); // Month of the year Like August.
$day = date('d', $timestamp); // Day of the month like 14
$year = date('Y', $timestamp); // A full numeric representation of a year, 4 digits like 2004
$hour = date('h', $timestamp); // The time in hours.
$minute = date('i', $timestamp); // The time in minutes.
$seconds = date('s', $timestamp); // The time in seconds.
$am_pm = date('A', $timestamp); // The Uppercase Ante meridiem and Post meridiem AM or PM.
$suffix = 'Eastern Time' ; // The suffix that you would like to attach at the end of your date and time.
$actualtimeis = "{$weekday}, {$month} {$day}, {$year} {$hour}:{$minute}:{$seconds} {$am_pm} {$suffix}" ;
return $actualtimeis ;
// function ends here.
}
echo actualtime (); // Prints something like Saturday, August 14, 2004 12:59:47 PM Eastern Time.
>
Days Between Now And Future Date - FreeThis will calculate and show how many days there are from the current date to a date in the future that you define. Calculating date differencesGiven two dates, you can use this function to calculate the difference between them in terms of the number of years, months, weeks, hours, minutes and seconds. Title Bar Date ScriptA code snippet that displays today's date in the title bar of your web page. Displaying the Current Date and TimeDisplaying the Current Date and Time. All data which may be obtained with command Date() is shown. A couple of examples are included: link of the day and local time Working with dates and times in PHPIn this tutorial, you will be introduced to dealing with dates in PHP. Page generation timeThis technique is very helpful when you try to optimize your PHP script. Just add a few lines of PHP code and you will get a report showing execution time of your script in milliseconds. Educadito v.phpPHP function to greet the user, according to the hour. Written in Spanish. Calendar of Events ListingThis tutorial describes how to write a simple script which looks at a list of events and only displays the events that occur today or in the future. Last Modified - Tutorial and Script - FreeThis is an example rich tutorial on adding a "last modified" date and time to your website. It includes full source code and description of its use. Inserting Dates - FreeThis basic tutorial shows four different ways of displaying date and time using PHP functions on your Web page. Adding Date/Time Last Updated - FreeSimple tutorial explains how to add date time stamp "page last updated on..." for a specified file using filemtime function. Date/Time Functions Demo - FreeThe PHP's date function is used to display times and dates in various ways. Here, you will learn how to use the date function to format and display dates and times.
|
A D V E R T I S E M E N T
|
Subscribe to SourceCodesWorld - Techies Talk |
| |
|