Showing cd_created as d-m-Y Issue

darrenhallinan 31 Jan, 2012
Any one know why this would not work?

<?php // convert date for user
echo date('d-m-Y',strtotime($row->cf_created));
?> 


Using it in a DB Multi Record Loader.

All i get as a result is

01-01-1970

Info

MYSQL 5 Feild: cf_modified Type: datetime

I had this issue before but never got to the end of it . . . but need to now
GreyHead 31 Jan, 2012
Hi darrenhallinan ,

What value is in $row->cf_created ? Try this to see what is happening:
<?php // convert date for user
echo'<div>$row->cf_created: '.print_r($row->cf_created, true).'</div>';
echo'<div>strtotime($row->cf_created): '.print_r(strtotime($row->cf_created), true).'</div>';
echo date('d-m-Y',strtotime($row->cf_created));
?> 


Bob
darrenhallinan 31 Jan, 2012
When I used the above code it resulted in :

$row->cf_created:
strtotime($row->cf_created):
01-01-1970


code must not be right, i change the ' to " around the echo statements thinking it might be that

<?php // convert date for user
echo "<div>$row->cf_created: '.print_r($row->cf_created, true).'</div>";
echo "<div>strtotime($row->cf_created): '.print_r(strtotime($row->cf_created), true).'</div>";
echo date('d-m-Y',strtotime($row->cf_created));
?>


but the just resulted in nothing been displayed

The value of the feild are date time format E.G: 2012-01-30 23:54:15 as set by chrono engine
darrenhallinan 31 Jan, 2012
I CAME ACROSS THIS
http://www.youtube.com/watch?v=3WQLHAwNPZY
Which work if i place this code in a custom code box:

<?php
function convert ($date) {
	$converteddate = date("M j, Y", strtotime ($date));
	return $converteddate;
}
?>


and put in the date using

<?php
 echo convert("2011-06-09 23:25:00"); 
?>


i get
Jun 09, 2011

But when I try

<?php
 echo convert(".$detail ['cf_created']."); 
?>


or

<?php echo convert ("$detail ['cf_created']"); ?>


or

<?php echo convert($row->cf_created); ?>


or

<?php echo convert("$row->cf_created"); ?>


the result is again:

Jan 1, 1970

Any ideas?
GreyHead 01 Feb, 2012
Hi darrenhallinan ,

It looks to me as though $row->cf_created is empty. Where are you getting this value from?

Bob
darrenhallinan 01 Feb, 2012
Hi Bob

I know that's what it looks like but the fields do have values

anyway I have made some headway

this works. . .

Form type: Custom

HTML code:

<?php
function convert ($date) {
   $converteddate = date("M j, Y", strtotime ($date));
   return $converteddate;
}
?>

<?php
echo convert("{cf_created}"); 
?>



Which surprised me to be honest - what a headache

anyway still have no solution for the multi record db using custom code
GreyHead 01 Feb, 2012
Hi darrenhallinan,

Hmm - I wouldn't have expected that to work either !!

Up to my eyebrows here but clearing posts when I can.

Bob
darrenhallinan 06 Feb, 2012
Same as that bob I reckon ill have to leave it just having the date on the detail page for now. . it just taken so much time to get that to work.

it would be nice but not necessary to have it on the list of results


As always Bob thanks for you help
darrenhallinan 06 Feb, 2012
OK just for those looking for same solution . . . and note to myself in the future if i ever return to it!!

This might work. . . not tested but just thought of it while replying to bobs post. .

Use the code that works above in the custom html box (not using the wizard)

and instead of adding your code using the custom code box in the on records found on multi db loader just add the "show html" to the on record found
This topic is locked and no more replies can be posted.