Dates in php

Get current date in PHP | Date format parameters | How to format a certain date in php
Today we will talk about dates in php language with some examples.

Get current date in PHP

To get the current dateĀ  you can write this code
date();

If you want to format the date in a certain way write something like this:
<date("Y.m.d");
As a separator you can put . – , _

Format parameters of date function

There are a few format parameters, but now we will remind about the most used ones.

If you and to display the day in date use the d parameter. Example: date(“d”);
If you and to display the month in date use the m parameter. Example: date(“m”);
If you and to display the year in date use the m parameter. Example: date(“Y”); if you want to display 4 digit year or date(“y”); if you want to display 2 digit year.
To display the hour, minutes and secods you can use date(“H:i:s”); Use H to display hour from 0 to 23 and h to display hour from 1 to 12. If you use h you can use after parameter A or a to display am or pm.

You can display the day of the year with z parameter date(“z”); or you can display the week of the year with the W parameter using date(“W”);

If you want the full list of date function format parameters you can check this link

How to format a certain date in php

Let’s say you want to write 14-10-2019 in a different way like 2019.10.14. You can do this using functions date() and strtotime() functions. This can be used to add a value formated in date to database.
You know what date function does, now let’s see what strtotime does.
strtotime converts English textual datetime description into a Unix timestamp. (Timestamp is the number of seconds since January 1 1970 00:00:00 UTC)
Now back to our example. To make what we want we will do something like this:
date("Y.m.d",strtotime("14-10-2019"));