Trying to format my date variable

I have a working php file, which use lots of custom dates.
I am try to simply format an echoed out put, with no success(very new to php).
hope someone can help.
[php]$rotaDate = date(‘23/2/14’);
$driverListDate = date(‘5/1/14’);[/php]

[php]//Calculate the differance between 2 dates
function dateDiffInWeeks($date1, $date2,$noOfLines){
$first = DateTime::createFromFormat(‘d/m/Y’, $date1);
$second = DateTime::createFromFormat(‘d/m/Y’, $date2);
return (((floor($first->diff($second)->days/7))/$noOfLines) - floor((floor($first->diff($second)->days/7))/$noOfLines))*$noOfLines;
[php]function customData($con,$num,$driverListDate,$rotaDate,$noOfLines,$line){
if($line==getNewLine($con,$num,$driverListDate,$rotaDate,$noOfLines)) {
//echo date(“jS F Y” );
//echo date(‘jS F Y’, $rotaDate);
return $rotaDate;

Im trying to echo my date as “jS F Y” format.
This of course is not my full php file, but im sure its all thats relevant.
Thanks in advance!

Before we get into anything, where are these dates coming from? Are they stored in a database and if so in what format? It is best to let the database do the work if so.

We need to avoid the XY problem. (Look it up if you dont know what it is.)

The date is setup as a variable in the php code, exactly as above shows.(top quotes)
The second quotes above, is(I think OO php) which I copied from the net. It uses the variable date and works and outputs the differance between 2 dates. Then I needed to format that date elsewhere. Done now by changing this date string to date object.
But now, a different mission adding days to dates. Keeps returning 1jan 1970.

I can’t get my head around these dates, I need to read more maybe.

If you store your dates in the mysql date or datetime format the database can do all the calculations which is much better than having php do it. You can output the date in any format you want from there.

Date format is YYYY-MM-DD
Datetime format YYYY-MM-DD HH:MM:SS

Do an update to your database. Ditch the Php code.

Sponsor our Newsletter | Privacy Policy | Terms of Service