--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Query;
+
+/**
+ * Sql function
+ */
+class SqlFunctionNOW extends SqlFunction {
+
+ protected static $category = self::CATEGORY_DATE;
+
+ protected static $dataType = 'Timestamp';
+
+ protected static function params(): array {
+ return [];
+ }
+
+ /**
+ * @return string
+ */
+ public static function getTitle(): string {
+ return ts('Now');
+ }
+
+ /**
+ * @return string
+ */
+ public static function getDescription(): string {
+ return ts('The current date and time.');
+ }
+
+}
}
}
+ public function testCurrentDate() {
+ $lastName = uniqid(__FUNCTION__);
+ $sampleData = [
+ ['first_name' => 'abc', 'last_name' => $lastName, 'birth_date' => 'now'],
+ ['first_name' => 'def', 'last_name' => $lastName, 'birth_date' => 'now - 1 year'],
+ ['first_name' => 'def', 'last_name' => $lastName, 'birth_date' => 'now - 10 year'],
+ ];
+ Contact::save(FALSE)
+ ->setRecords($sampleData)
+ ->execute();
+
+ $result = Contact::get(FALSE)
+ ->addWhere('last_name', '=', $lastName)
+ ->addWhere('birth_date', '=', 'CURDATE()', TRUE)
+ ->selectRowCount()
+ ->execute();
+ $this->assertCount(1, $result);
+
+ $result = Contact::get(FALSE)
+ ->addWhere('last_name', '=', $lastName)
+ ->addWhere('birth_date', '<', 'DATE(NOW())', TRUE)
+ ->selectRowCount()
+ ->execute();
+ $this->assertCount(2, $result);
+ }
+
public function testRandFunction() {
Contact::save(FALSE)
->setRecords(array_fill(0, 6, []))