When working in any programming language, dealing with dates and time is a simple task. That is, until time zones have to be supported. PHP’s time () function gives you all the information that you need about the current date and time. It requires no arguments but returns an numeric value.

If you will call to time() function which will return a set of numeric values which is difficult to understand. So to make it easy we can have time format along with the date() function.

<?php

$today = date(“d/m/Y”);

echo “Today is “.$today;

?>

We can use different time format with separator like d-m-Y, d.m.Y and so on.

Display Current Date and Time:  We can use the following characters to format the time string:

<?php

echo date(“h:i:s”) . “<br>”;

echo date(“F d, Y h:i:s A”) . “<br>”;

echo date(“h:i a”);

?>

Here h-hour in 12-hour format, H – hour in in 24-hour format, i – minutes, s – seconds, a -am, pm(Lowercase) and  A – Represent AM, PM (Uppercase)

So it is easy to get the current year by putting the following line- <?php echo date(“Y”);?>?>

The PHP time(): The time() function is used to get the current time as a Unix timestamp

Example: 

<?php

$cDate = 1394003958;

echo(date(“F d, Y h:i:s”, $cDate));

?>

Example: To print date like 10 July 2015

<?php

$date1 = date_create(―2016-05-10”);

echo date_format($date1, ‘j-F-Y’);

?>

 Output: 10 May 2016

author image

About admin

You Might Also Like...

NEED OF DIGITAL MARKETING
Hirdesh Bhardwaj

11 Comments

  1. Excellent way of describing, and nice post to obtain data concerning my presentation focus, which i am going
    to convey in college.

  2. I go to see daily some websites and blogs to read articles, except this blog gives feature based posts.

  3. Also a large amount of lawnmowers tend not to cut a broad enough area and you get going over the same area
    several times simply to attempt to obtain it
    cut. If the second story can be an option, this might be yet another excellent
    spot to add your spare room because it will likely be set
    aside from the family room, kitchen and dining areas that are probably on the first floor.

    Being cordless, makes this tool probably the most appropriate to use in dangerous areas like inclined walls, rooftops etc.

  4. Toll gemachte Seite, das Layout gefaellt mir echt gut!
    War bestimmt ‘n haufen Arbeit.

  5. Remarkable! Its genuinely amazing post, I have got mucch clear idea regarding fdom
    this piece of writing.

  6. happy new year images 2019

  7. Thanks for sharing such a great information with us. Your Post is very unique and all information is reliable for new readers.
    Keep it up in future, thanks for sharing such a useful post.
    Happy New Year 2019 Animated Gifs

  8. thanks for the data

  9. ver good article…

  10. thanks for sharing php date functions, its amazing and working code.

Leave a Reply

Your email address will not be published.

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+2k
Google+
http://hirdeshbhardwaj.com/2017/03/29/php-datetime-functions
YouTube75
YouTube