Jump to content

PHP Dates - from MYSQL yyyy-mm-dd to dd-mm-yyyy


petenetman

Recommended Posts

I’m using this string

$oDate = strtotime($row['CompletedIT']);

$sDate = date(“d/m/y”,$oDate);

echo $sDate

 

to get the MYSQL date value stored in the table row ‘CompletedIT’.

 

The database value is 2010-07-22 but I get the echo return of 01/01/70

 

Can someone give me an idea as I want to display the date as dd/mm/yyyy

 

Thanks in advance

 

The way I do it is like:

 

$now = date('Y-m-d');

$oned = strtotime("$now +1 day");

$oned = date('d/m/Y', $oned);

 

so for your solution it would be

 

$oDate = strtotime("$row[CompletedIT]");

$sDate = date("d/m/Y, $oDate);

echo $sDate;

 

that should work theoretically.

Using

 

$oDate = strtotime($row["CompletedIT"]);

$sDate = date('d/m/y',$oDate);

echo $sDate

 

gives me the echo return of 01/01/70

 

when the date stored is 2010-07-22

 

Does the 01/01/70 indicate something like PHP can't find the recor?

 

I've been on this all day now and I think I am going round in circles.

$rows["CompletedIT"];  is not the same as $row[CompletedIT]

 

What is your actual code that fetches the result from the query?

 

You might want to reread the reply that Pikachu2000 made because using the mysql DATE_FORMAT() function directly in your query is both simpler and at least 8x faster than trying to do this using php code.

If you were developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON, php would help you find things like variable names that are different than what you are actually using because they would show up as undefined variable errors due to the name mismatch. You will save a ton of time.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.