Home => PHP Projects => Dates/Times  
Dates and Times in P H P

Using very little PHP, this project will produce the following output at the bottom of a web page

  The time on your computer is: hh:mm:ss AM
  The time on the web server is: hh:mm:ss PM
  Prior to you, the last person to look at this web page did so at: hh:mm:ss PM

The first line is produced on your computer, the last two lines are produced on the web server machine by PHP. The heart of the issue is producing the last line, a record of the last time each web page was viewed. 

The first line comes from client side JavaScript that looks like this: 

  <script language="JavaScript">
  tempdate = new Date();
  document.write("The time on your comptuer is: " + tempdate.toLocaleString() +"<br>");
  </script>

Here is the output the above script produced for you, now:
   

PHP has a date function that can be used to externalize the date on the web server computer. For example, this PHP code:
      echo date ("l dS of F Y h:i:s A")
Prints something like: Wednesday 15th of January 2003 05:51:38 AM

The PHP date function, output right now is:
      The time on the server is: Friday, July 30, 2010 8:19:42 PM

 

 Viewed 3861 times since May 26,2010 (59 per day over 65.2 days) Home => PHP Projects  
Page: www.michaelhorowitz.com Last Updated: May 24, 2005 5 PM  
Prior to you, the last person to look at this web page did so on Friday, July 30, 2010 8:19:29 PM
Current time on the server is Friday, July 30, 2010 8:19:42 PM

There have been 115249 page views of these PHP pages since February 10, 2004 for an average of 49 per day over 2,362.0 days
The last 5 people to view this web site were from these IP addresses:
38.107.191.89no name found
38.107.191.86no name found
195.62.15.206no name found
64.8.98.179no name found
178.107.220.58no name found