When i run the following code
echo date('l jS \of F Y', strtotime('22/08/2018'));
the output is
Thursday 1st of January 1970
Any ideas why?
It is to do with the difference between US an European date formats.
With slashes strtotime
reads MM/DD/YY with hyphens it reads DD-MM-YY
Replacing the slashes with dashes will tell it to use the correct format.
echo date('l jS \of F Y', strtotime('22-08-2018'));
Will print Wednesday 22nd of August 2018
...Forward slash (/) signifies American M/D/Y formatting, a dash (-) signifies European D-M-Y and a period (.) signifies ISO Y.M.D.
From the most up voted User Contributed Notes on: https://secure.php.net/manual/en/function.strtotime.php
The reason you get that output is because strtotime can't parse the date.
If you look in the manual it has a list of what date formats that can be parsed.
If you must use that date format you can use date_create_from_format to parse it.
$datetime = date_create_from_format ( "d/m/Y" , $dateString);
This returns a DateTime object that you can manipulate as you wish.
Example:
$dateString = '22/08/2018';
$datetime = date_create_from_format ( "d/m/Y" , $dateString);
echo date_format ( $datetime , 'l jS \of F Y' );
Will output:
Wednesday 22nd of August 2018