I had a global search function on a quoting website from which I wanted to be able to search on all details of a quote (quote references, vehicle details, customer details etc.) including the created dates using only the single input text value:

This means that I definitely don't want to enumerate the results before attempting to cast the date to the appropriate string format.
In an attempt to do this, I've come up with the following:
// this is obviously only a fragment of my actual query
_context.Quotes
.Where(q => string.Concat(
q.DateCreatedUtc.Day < 10 ? "0" : "",
q.DateCreatedUtc.Day,
"/",
q.DateCreatedUtc.Month < 10 ? "0" : "",
q.DateCreatedUtc.Month,
"/",
q.DateCreatedUtc.Year
)
.Contains(searchTerm));
I can confirm this translates to a database operation using EF Core V5 and Pomelo V5 with a MySql database.
The generated SQL looks something like this:
WHERE
LOCATE(@search_term, CONCAT(
CASE WHEN EXTRACT(DAY FROM `quote`.`date_created_utc`) < 10 THEN '0' ELSE '' END,
CAST(EXTRACT(DAY FROM `quote`.`date_created_utc`) AS CHAR),
'/',
CASE WHEN EXTRACT(MONTH FROM `quote`.`date_created_utc`) < 10 THEN '0' ELSE '' END,
CAST(EXTRACT(MONTH FROM `quote`.`date_created_utc`) AS CHAR),
'/',
CAST(EXTRACT(YEAR FROM `quote`.`date_created_utc`) AS CHAR)
)) > 0
This entire query has turned into a bit of a Frankenstein though and I am seriously questioning the value of allowing users to search on the dates.