Formatting date output

chriso0258 06 Jun, 2012
In the "Front List Settings" - "Custom Listing Settings" section, I have the following in the body section:

<table class="gridtable">
<tr>
<td width=80>{first_name}</td>
<td width=80>{last_name}</td>
<td width=300>{family}</td>
<td width=180>{item_name}</td>
<td width=100>{mbrshp_date}</td>
<td width=100>{expires}</td>
</tr>
</table>


Both mbrshp_date and expires are dates in this format: YYYY-MM-DD. I would like them in this format: Jun 14, 2012.

I have tried several php codes such as:

<td width=100>
<?php 
$date = date('M d, Y', {mbrshp_date});</td>
echo $date;
?>


but they aren't working here. I think I'm not understanding the correlation with the mysql table. Can I even use php code here and if so, what should work here?

Thanks.
GreyHead 06 Jun, 2012
Hi Chriso0258,

You can't usually mix curly brackets and PHP but I think that you can use PHP. The data will be in $row['column_name'] in the latest release so something like
<?php
$expires = strtotime($row['expires']);
$expires = date('d-m-Y', $expires);
?>
. . .
<td width='100' ><?php echo $expires; ?></td>
should to the trick (with the correct data format string).

Bob

Updates from Max's post after this one.
Max_admin 07 Jun, 2012
Hi,

Just a small fix, its:
$row['column_name']
but not
$row->column_name


:)

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
quantum_leap 06 Jul, 2012
Hi, I have a similar problem. I am using the following code in my form to poplulate a dropdown list with course availability:
<?php
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$query = "
SELECT `id`, `location`, `date`, `places_available`, `rel`
FROM `#__training_courses`
WHERE `course_name` = '2 Day Refresher Training'
ORDER BY `course_name`;
";
$db->setQuery($query);
$options = $db->loadAssocList();
foreach ( $options as $o ) {
echo "<option id='".$o[id]."' value='".$o[date]." - ".$o[location]."' rel='".$o[rel]."'>".$o[location]." - ".$o[date]." - Places available: ".$o[places_available]."</option>";
}
?>


The output is:

Dubai - 2012-7-27 - Places available: 13
Edinburgh - 2012-3-12 - Places available: 23



etc...

I would like to change my code so that the output is:

Edinburgh, March 9 - Places available: 23



Basically I would like to extract the full textual representation of a month from date(). I've tried using
.$o[date("F")]
but it didn't work!
GreyHead 07 Jul, 2012
Hi quantum_leap,

Try
foreach ( $options as $o ) {
  $date = date('F', $o['date']);
  echo "<option id='{$o['id']}' value='{$date} - {$o['location']}' rel='{$o['rel']}'>{$o['location']} - {$date} - Places available: {$o['places_available']}</option>";
}

Bob
quantum_leap 07 Jul, 2012
Unfortunately this always outputs January(even when January was not the month of the date).
quantum_leap 07 Jul, 2012
Nailed it!

$date = date('F', $o['date']);

needs to be

$date = date('F', strtotime($o['date']));

.

Cheers for the pointers though!
GreyHead 08 Jul, 2012
Hi quantum_leap,

Well done, that's right, you need a timestamp for the date() function not a date-time string.

Bob
megana 13 Aug, 2012
Question about this...my date is also my edit field. If I change {mydate} to <?php echo $row['mydate']; ?> so that I can customize the output, how will the edit link work?
GreyHead 13 Aug, 2012
Hi megana,

I suspect that it will work OK - but I'm not certain. Keep a backup and test.

Bob
megana 17 Aug, 2012
Yeah, it removed the edit link. How can I use PHP to generate it?
GreyHead 18 Aug, 2012
Hi megana,

Where are you using this and what code do you have at present?

Bob
megana 20 Aug, 2012
Hi Bob,

In the "Front List Settings" - "Custom Listing Settings" section:

<td class="in-month">{checkbox} <?php echo date("N",strtotime($row['lunchdate'])); ?></td>
GreyHead 22 Aug, 2012
Hi Megana,

That code looks OK and I guess that you can add an edit link to it - but I don't' know what code is needed for an edit link in the new version of CC. In the old one I'd just have added an <a . . .> </a> link around the date code.

Bob
This topic is locked and no more replies can be posted.