Can anyone please explain me the second argument of date function ?
string date ( string $format [, int $timestamp = time() ] )
What is it do,I mean what is it meant for ? I never used it except today when I had to do the following :
echo date('Y-m-d',strtotime('+1 day'));
By default date()
assumes you are referring to "now". If you want to use date with any other datetime other than "no" then you need to specify it using a timestamp.
var_dump(date("Y-m-d") === date("Y-m-d", time())); // bool(true)
Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time().
So if you leave it blank, you will echo the current date in the chosen format.
If you do as you do in your example and specify a timestamp it will format the specified timestamp. Your strtotime function converts +1day to an integer or timestamp format.
This mean that you can represent unix time as string in any format. Unix time you can get from database or with strtotime.
The second parameter defaults to the current date/time.
So, if you want to print the current date, don't pass the second parameter:
echo date('Y-m-d');
If you want to print something other than the current date/time, like the date of one week from today:
echo date('Y-m-d', strtotime('+7 days'));