Coding > PHP > Time and Dates Example
PHP: Time and Dates

Time and date retrieving and formatting is easy in PHP.

For example, you loaded this page at 07:15 Central Time. It is the 12 of May and the year is 2021.

All of the bold text was actually printed onto the screen using PHP rather than markup, such as HTML. In all programming languages, you can also return the number of days from a certain date. This can be fun and very useful in the case of special events among other things.

There are 53 days until 4th of July. Additionally, there are 172 days until Halloween.

How many days until next year? Well, next year will be 2022 and New Year's Eve is 233 days away!

This is all being calculated based on the given date, year, or time that was generated by your computer. It can be set to use a default timezone or retrieve the timezone based on your location if functionality, and obviously security, is built in.

With Laravel, programming code can be further minimized and organized by processing all this retrieving and formatting within classes and functions and passing only the variable to this page, which is the View. Directly from a Controller, this View is fed the data.

In addition to standard PHP, Laravel is a framework that boasts MVC (Model-View-Controller), which is a very long topic on its own, it also has its own template language: Blade. This makes it easy to reference the variables in very little code and more readability so long as those variables and/or data are passed to the View appropriately.

PHP Holidays - "Days Until" Table
Holiday Date of Holiday Days Remaining
New Years Day January 01 234
Valentine's Day February 14 278
Memorial Day May 29 17
Independence Day July 04 53
Labor Day September 04 115
Halloween October 31 172
Veterans Day November 11 183
Christmas December 25 227
New Years Eve December 31 233