createdDate for Multi-Record Tables

4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 16, 2012   (RSS)

Re: [northernpenguin] createdDate for Multi-Record Tables

By (Deleted User) - March 16, 2012 - edited: March 16, 2012

Hi northernpenguin,

createdDates can be compared easily enough to find the most recent update, but you can also change the order in which multiple records are pulled from the table so that the most recent is first (or last, as needed) and that way you know exactly where in the results array the record (and createdDate) are located.

To set the sort order of a multi-record table, click on Admin->Section Editors->[Appropriate Section]->Sorting and then add the desired sort pattern (in this case, "createdDate DESC").

Now when the records are retrieved the most recent record will be first (position 0).

If you already have a sort and can't use the above method, you can compare createdDates using the following:

list($records, $recordsMetaData) = getRecords(array(
'tableName' => 'multiRecordsTable',
));

// Set variable to store createdDate
$mostRecentCreatedDate = 0; // technically this date is Dec 31, 1969 - the beginning of the Unix epoch

// Go through each returned record and find the most recent createdDate
foreach ( $records as $record ) {
$createdDateAsTimeStamp = strtotime($record['createdDate']);
if ( $createdDateAsTimeStamp > $mostRecentCreatedDate ) { $mostRecentCreatedDate = $createdDateAsTimeStamp; }
}


Now you can print or echo the variable $mostRecentCreatedDate as the most recent updated record date.

Hope this helps,

Tom

Re: [Tom P] createdDate for Multi-Record Tables

Thanx Tom! Exactly what I needed. However, I did find one typo: strtotime is misspelled.

Thanx again!
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] createdDate for Multi-Record Tables

By (Deleted User) - March 16, 2012

Hi northernpenguin,

Thanks for the spot! I'll put that one down to "it's too early" - fixed it now.

Tom