I made a UDF in my Azure CosmosDB so that I can query records where the Timestamp field equals a certain year.
For example, my query looks like this:
SELECT * FROM c WHERE c.StaticKey = 'd6c5a92203d84ce28b94cfc64a6ad4ce'
AND udf.YEAR(c.Timestamp) = '2020' OFFSET 0 LIMIT 1
But for some reason my query always returns 0 results. I have a lot of records in my table that have a datetime from this year.
This record for exmaple DOES return 1 row and prints 2020:
SELECT udf.YEAR(c.Timestamp) FROM c WHERE c.StaticKey = 'd6c5a92203d84ce28b94cfc64a6ad4ce' OFFSET 0 LIMIT 1
My UDF in Azure looks like this:
function YEAR(datetimeString){
var datetime = new Date(Date.parse(datetimeString));
return datetime.getFullYear();
}
The column Timestamp contains datetime values looking like this: 2020-10-20T07:13:22.802346.
As you can see in this fiddle the javascript function works good: https://jsfiddle.net/0eozyhnv/
Anyone any idea why my UDF isn't working in my WHERE clause?