Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
Formatting the Current Date and Time in PHP
Sep 26, 2018 @ 15:56:18

On the TutsPlus.com site they've posted a tutorial (by author Monty Shokeen) covering the use of PHP's built-in functionality to format date and time values such as the current date.

You'll often want to work with dates and times when developing websites. For example, you might need to show the last modified date on a post or mention how long ago a reader wrote some comment. You might also have to show a countdown of the days until a special event.

Luckily, PHP comes with some built-in date and time functions which will help us do all that and much more quite easily.

The tutorial starts with the basics of datetime handling in PHP, making use of the date function to get formatted output of either the current time or the timestamp provided. Several code examples are provided showing the output for month/day/year and hour/minute/second combinations. Next they look at how to get the current Unix timestamp, using that to calculate day differences and working with relative time strings.

The tutorial ends with a look at the DateTime functionality also included in PHP and provides several examples of it in use for both formatted date output and calculating time differences.

tagged: datetime date time formatting calculation tutorial

Link: https://code.tutsplus.com/tutorials/working-with-date-and-time-in-php--cms-31768


Trending Topics: