Home » PHP

Displaying date and time

23 March 2008 101 views Popularity: 1% Share/Bookmark

email

I find timestamp more flexible to use. Using time function which returns current Unix timestamp. We have the flexibility to change the timestamp according to the display requirement for our date and time by using date function.


<span id="more-49"></span>

<?php

//getting current unix timestamp from time() function
$time = time();
echo "Current Unix timestamp: ";
echo $time;
echo "<br/><br/>";

//manipulating the current timestamp with date() function
$date = date("F d, Y h:i:s",time());
echo "Current Date and Time: ";
echo $date;
echo "<br/><br/>";

?>

One more PROBLEM

Suppose that we have 3 selection list. First for months, second for days, and third for years. Now, we want to insert the date obtained from these selection list into our database.

The solution is by using strtotime() function. This function parse about any English textual datetime description into a Unix timestamp.


<?php

// Suppose we got these data from our selection list
$month = "February";
$day = 14;
$year = "2008";

// using strototime() function
$str_time = strtotime("$day $month $year");
echo "Unix timestamp from strtotime function: ";
echo $str_time;
echo "<br/><br/>";

?>

Related posts:

  1. Magento: Sort latest product by ‘created date’ and ‘new from date’
  2. Random number, string generation in PHP
  3. PHP Javascript : Playing with multi-dimensional array
  4. Magento: Displaying / Adding Gift Message in Order
  5. jQuery: Grey out background and preview image as popup
  6. PHP : Read Write Xml with SimpleXML
  7. PHP: How to get stock quote data from Yahoo! Finance? (Complete Code and Tutorial)
  8. Simple and easy jQuery tabs with AJAX and PHP
  9. Making a tree navigation menu in PHP
  10. ASP.NET Error : An HtmlSelect cannot have multiple items selected when Multiple is false.