Reputation: 154
i have configuration in news tca like:
'ctrl' => [
'tstamp' => 'tstamp',
'crdate' => 'crdate',
with this, news will be saved like 1535967103
in database, with hours, minutes and seconds. I want trim this information and have it like 1535932800
How can i get this in TCA configuration?
Upvotes: 0
Views: 262
Reputation: 154
Ok, i created new field with datetime, its take the same value as crdate.
then i created processDatamap_preProcessFieldArray(&$fieldArray, $table)
where i do:
$dateTime = (new \DateTime())->setTimestamp($fieldArray['datetime']);
$dateTime->setTime(00, 00, 00);
$fieldArray['datetime'] = $dateTime->getTimestamp();
in ext_localconf
i added:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['si_news'] =
\Sozialinfo\SiNews\Hooks\TCEmainHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['si_news'] =
\Sozialinfo\SiNews\Hooks\TCEmainHook::class;
and now i have crdate without hours, minutes and seconds(in new field, crdate untouched) and i can do sorting with this field.
The only solution for remove seconds from crdate which i found is to use processDatamap_afterDatabaseOperations
and use custom query with $GLOBALS['TYPO3_DB']
. Its little dirty IMO.
I use new field instead overwrite crdate because as someone said: crdate is an internal TYPO3 field. So i didn't change internal TYPO3 field.
Thanks all for help.
Upvotes: 1
Reputation: 2684
You can always sort by day, even with timestamps having seconds. The rest of the sorting criteria for identical timestamps usually will be the autoincrement field, so the result of ascending or descending sorting by timestamp will be the same.
Unless you want to group by a certain day, having another timestamp would not make any difference.
Anything else can be done in the frontend output, so you can skip the seconds while formatting the timestamp via date or strftime.
Upvotes: 1
Reputation: 1003
tstamp and crdate can not be rounded. They're always per second.
Upvotes: 0