I am writing a module that displays a count of the number of records depending on the date_time
column. I am able to get the result that I am looking for when using a static date as below. However, I am unable to get the correct response from the code in the second block.
{
$date = JFactory::getDate();
$cur_year = JHtml::_('date', $date, 'Y');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)')
->from('#__aa_job_data')
->where("date_time LIKE '2017%'");
$db->setQuery($query);
$count = $db->loadResult();
return $count;
}
The code below isn't working I can't work out the correct syntax to use for adding $cur_year
& %
while wrapping it in ''
{
$date = JFactory::getDate();
$cur_year = JHtml::_('date', $date, 'Y');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)')
->from('#__aa_job_data')
->where("date_time LIKE $cur_year%");
$db->setQuery($query);
$count = $db->loadResult();
return $count;
}
What is the correct method to write the WHERE statement?