Cs.search - comparing date values in filters

Hello

How do I format a JS Date value for use in filter of cs.search()?

I want to filter to my search to only return records whose ‘expiry date’ property (timestamp datatype) is greater than now.

My now value is generated via JS Date. I’ve tried formatting it every which way but having no luck.

Switched my property to a date & time datatype, using that in the filter throws an ‘Invalid filter’ error.

It’s all good I figured it out, remembered that Create likes its timestamps without milliseconds :slight_smile:

So the solution for anyone wondering:

		let now = Date.now()
		let nowStamp = Math.round(now/1000)

		let filters = [
			{'field_path': cs.ref('field_expiry_time'), 'comparator': 'greater_than', 'value': nowStamp},
		]
1 Like

Thanks for sharing your solution, every bit of context and info is helpful.
I’ve had plenty of my own challenges dealing with dates and times in code studio (more to do with javascript than Create to be fair).
The context that “Create likes its timestamps without milliseconds” is super helpful!
Sometimes we don’t know what we don’t know :wink: