PHPEveryday.com PHP and Web Development Tutorial
What are you looking for?


PHP Date Time: Getting Current


PHP Date Time Tips - Part 1: If you want to display current date and/or time, you can try code like this:
<?
$now = getdate();
?>

It create array that contents information about current date time. To look what content of the array, you can try like this:

<?
$now = getdate();

print_r($now);
?>

So, you can see:

Array ( [seconds] => 20 
        [minutes] => 56 
        [hours] => 15 
        [mday] => 20 
        [wday] => 4 
        [mon] => 3 
        [year] => 2008 
        [yday] => 79 
        [weekday] => Thursday 
        [month] => March 
        [0] => 1206053780 )

Thus, you can use like this:

<?
$now = getdate();

echo "current date is ". 
      $now['mday'] . " ".
	  $now['month']. " ".
	  $now['year'];
echo "<br />";
echo "current time is ".
      $now['hours']. ":".
	  $now['minutes']. ":".
	  $now['seconds'];
	  
?>


Series this article:
PHP Date Time: Getting Current
PHP Date Time: Checking Date Validity
PHP Date Time: Formating Timestamp
PHP Date Time: Converting Strings to Timestamps
PHP Date Time: Using English-language time descriptors
PHP Date Time: Checking Leap Years
PHP Date Time: Finding The Number of Days in a Month
PHP Date Time: Finding the Day in Year Number for a Date
PHP Date Time: Finding The Number of Weeks in Year Number for a Date
PHP Date Time: Finding the Day Name for a Date
PHP Date Time: Finding The Total Number of Days in Year
PHP Date Time: Finding The Total Number of Weeks in Year
PHP Date Time: Converting Local Time to GMT
PHP Date Time: Converting Between Different Time Zones
PHP Date Time: Finding the Year Quarter for a Date
PHP Date Time: Converting Minutes to Hours
PHP Date Time: Comparing Dates


Tag: date, time, date time, current Category: PHP Basic Post : March 20th 2008 Read: 2,694 Bookmark and Share

blog comments powered by Disqus


Database Tutorial
  • Learn PHP MySQL
  • Learn PHP ADOdb
  • Learn PHP Data Object/PDO
  • Learn PHP XML
  • Learn PHP SimpleXML
Security Tutorial
  • Learn PHP Security
  • Learn HTTP Authentication
  • Learn PHPSecureSite
Framework Tutorial
  • Learn CodeIgniter
  • Learn Joomla
  • Learn Smarty
  • Learn Zend Framework
Template Tutorial
  • Learn Joomla Template
  • Learn WordPress Template
API Tutorial
  • Learn Facebook
JS Framework Tutorial
  • Learn MooTools
  • Learn JQuery
AJAX Tutorial
  • Learn AJAX in 10 Minutes
  • Learn AJAX Client Side
  • Learn AJAX PHP
  • Learn AJAX Remote Server
  • Learn AJAX Repetitive
  • Learn AJAX MySQL
  • Learn AJAX Grid
Web Services Tutorial
  • Learn Web Services NuSOAP
  • Learn Web Services WSDL
  • Learn Web Services WSDL Array
  • Learn Web Services .NET Grid
  • Learn Web Services WDDX
Package Post
  • Joomla Intro
  • Joomla Component
  • Joomla Module
  • Joomla MVC
  • Joomla MVC Backend
  • PostNuke Intro
  • Zend Framework Intro
  • Zend Framework Action
  • Zend Framework Database
  • Zend Framework Registry
  • Zend Framework Config
  • Zend Framework Login
  • Zend Framework Session
  • PHP Array Tips
  • PHP File Tips
  • PHP Email
  • PHP Ms Excel
  • PHP Pattern
  • PHP SMS
  • Flash Database
  • PHP Multitier
  • jQuery Introduction
  • jQuery Selectors
  • Portable Web Server
  • Web Mobile Intro
  • Drupal Installation
  • Drupal Configuration