Forums

Split recordtime

navajofra 05 Apr, 2010
How I can split {recordtime} in CC to date and time?
I already tried:
<?php 
$d='{recordtime}';
$datum = left($d,10);
?>
<td width="70 px"><?php echo $datum; ?></td>

But it doesn´t work. As a result I get 'recortime}'
GreyHead 05 Apr, 2010
Hi navajofra,

I think that you need to use the $MyRow data object to use the data in PHP. Here's a code snippet that I wrote to re-format dates in the CC Body section. In your case you need to add the left() line to select the date part of the date-time string:
// reset dates to m/d/Y format
$dates = array( 'first_date', 'second_date');
foreach ( $dates as $v ) {
    $k = $v.'_mdy';
    $MyRow->$k = '';
    $date = $MyRow->$v;
    if ( $date ) {
        $date = explode('-', $date);
        $date = $date[1].'/'.$date[2].'/'.$date[0];
        $MyRow->$k = $date;
    }
}
?>
. . .
<td><?php echo $MyRow->first_date_mdy; ?></td>

Bob
navajofra 05 Apr, 2010
I tried the suggested code. However I think it doesn´t fit exactly my needs.

What i like to show in the CC form is only the date of each record:

I put to Connection view settings of the body field:
<tr>
<td width="70 px">{recordtime}</td>
</tr>

As a result i get: 2010-04-03 - 18:12:28

But i want to show only 2010-04-03
what is the coding for showing it?

I think there doesn´t need to be a "foreach", because CC already fetched the actual record from the table.
GreyHead 05 Apr, 2010
Hi navajofra,

No it doesn't exactly fit your needs but you can easily adapt it to do what you need. All the necessary code is there.

Bob
navajofra 05 Apr, 2010
ok. I will try it. Thx GreyHead
navajofra 05 Apr, 2010
Hallo GreyHead,
I understand the coding now. But how can I get the content of the field recordtime?
with $date='{recordtime}' it works, but I cannot explode $date. The result of the date[0] is always the content of {recordtime}. date[1] and date[2] are empty.

How can I ask for the actual content of the field recordtime using php code in Connection View Settings-Body?
GreyHead 05 Apr, 2010
Hi navajofra,

You probably don't need to explode recordtime, just take out the substring. A MySQL date-time field value is usually in the form YYYY-MM-DD HH:MM:SS but for some reason ChronoForms uses YYYY-MM-DD - HH:MM:SS

Look in the database record to see what form at your fields take.

Bob
navajofra 05 Apr, 2010
My problem is only how to get out the date from the recordtime field of the current record if I use the body of Connection View Settings.

I assume chronoconnectivity has already stored the current record to an array as $row->recordtime or something else.
I don´t know the name of the array so that I could use it instead of {recordtime} in the Connection view settings.
I know the Connection view settings body is only a template for displaying the records.
Can I put the code into the body or where else?
GreyHead 05 Apr, 2010
Hi navajofra,

I expect that it is stored as a string - look at the database table with PHPMyAdmin or EasySQL or the ChronoForms DataViewer to check.

You can run PHP inside the CC Body box (but not MySQL queries).

Bob
navajofra 06 Apr, 2010
Yes it is saved as a string. what shall I do?

Btw i can run MYSQL queries in the CC Body box.
But only the first record of a table gets displayed. I don´t know the reason.
Maybe it is my coding.

<?php

$database->setQuery( "SELECT * FROM #__chronoforms_profile WHERE cf_id = cf_id LIMIT 1" );

$categories = $database->loadObjectList();
foreach($categories as $category) {
$date=explode(" ",$category->recordtime);
echo '<td width="80 px">'.$date[0]."</td>";
}

?>
Lapo 16 May, 2010
Hi,
I've the same problem.
Mr GreyHead, write the solution please!

Thanks...
navajofra 17 May, 2010
Solution:
<?php
$date=explode(' ',$MyRow->recordtime);
echo $date[0];
?>
This topic is locked and no more replies can be posted.