PHP Date and Time Formatting Functions

Mysql Mysqli php Programming Technology

PHP Date and Time Formatting Functions

In this Post We Will Explain About is PHP Date and Time Formatting Functions With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to PHP Date and Time FunctionExample

In this post we will show you Best way to implement Formatting Dates and Tiems in PHP, hear for Getting the Time Stamp with time using PHPwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

You can download source code and Demo from below link.

declaration of date

Returns a simple string formatted simple using PHP according to the given some format string using the given integer with php date timestamp or the get current time if no simple timestamp is given. as well as In other words, means syntex of the $timestamp is optional and defaults to default the value of time() Like as a Date and time formatting with PHP.

string date ( string $format [, int $timestamp ] )

Example : Date and Time Formatting with PHP
2018-02-09 16:45:58
Feb 09 18 4:45:58 pm

Date formatting with PHP

Not many people can simple read this clearly any date error without any problems. This is simple the current server time.Please all the formats check Now see this:

echo date("d-m-y", time());     	// 09-02-18
echo date("D j/n/Y", time());     	// Thu 7/2/2018
echo date("jS of F Y", time());     // 9th of February 2018
echo date("d M y", time());     	//09 Feb 18
echo date("l jS of F", time());     // Thursday 9th of February

Time formatting with PHP

echo date("G:i:s", time());      //16:30:58
echo date("H:i:s", time());    	 //16:30:58
echo date("g:i a.", time());     //4:30 pm.
echo date("h:i A.", time());     //04:30 PM.

Date and time formatting with PHP

echo date("l jS of F g:i A.", time());    // Thursday 9th of February 4:30 PM.
echo date("D M j G:i:s T Y", time());     // Thu Feb 9 16:30:58 EET 2018

PHP Date Formatting Custom Functions

<?php  
$start = "30-08-2017 07:08 PM";
$end = "30-08-2017 07:08 PM";
echo "<pre>";
print_r(createRange($start, $end, $format = 'd-m-Y H:i:s'));
echo "</pre>";

function createRange($start, $end, $format = 'd-m-Y H:i:s') {
    $start  = new DateTime($start);
    $end    = new DateTime($end);	
    $invert = $start > $end;

    $dates = array();
    $dates[] = $start->format($format);
    while ($start != $end) {
        $start->modify(($invert ? '-' : '+') . '1 day');
        $dates[] = $start->format($format);
    }
    return $dates;
}
?>

Example

I hope you have Got What is Date formatting with date() function for PHP Code Example And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Date Range Search Jquery DatePicker using Ajax PHP with MySQL
  2.   Simple PHP Convert Date Format Examples
  3.   10 little Importance PHP functions list with Example
  4.   How to install localhost/codeigniter/ with XAMPP
  5.   Vue Shopping Cart - VueJS Shopping Cart - vue js e-commerce
  6.   PHP Tutorial
  7.   How to convert date format in PHP?
  8.   PHP cURL HTTP Request (GET & POST)
  9.   JavaScript Array Methods tips, tricks and examples
  10.   Working with datetime in PHP Examples

Leave a Reply

Your email address will not be published. Required fields are marked *