How to format date in PHP?

I am currently working on a PHP project. I am not an experienced PHP developer so I have a lot of doubts. One of them is how can I format the date in PHP the way I want. For example, if I want to put the date in YYYY-MM-DD in format, what is the syntax to do that. Can anyone tell me the PHP functions to format the date?

You can output a formatted date in PHP using the date() function. For your specific case, you have to use the following code.

date("Y-m-d");

This will output the current date in the YYYY-MM-DD format.