[TYPO3-mvc] How to add a SQL function in a query

Bastian Waidelich bastian at typo3.org
Fri Sep 16 11:20:37 CEST 2011


Rayuth You wrote:

Hi Rayuth,

>> $query->equals('YEAR(crdate)','2011')),

Nice idea, but that will only return records with the crdate (timestamp) 
being equal to exactly 1293861600.

Instead you could find out the start- end end timestamp of the given 
year, eg with:

$year = 2011;
$startTimestamp = mktime(0, 0, 0, 1, 1, $year);
$endTimestamp = mktime(23, 59, 59, 12, 31, $year);

$query->matching(
	$query->logicalAnd(
		$query->greaterThanOrEqual('crdate', $startTimestamp),
		$query->lessThanOrEqual('crdate', $endTimestamp),
		$query->equals('name','blabla')
	)
)->execute();

(untested)

HTH,
Bastian


More information about the TYPO3-project-typo3v4mvc mailing list