Filter if dob is today through ODATA(version2) through $filter when date is in unix timestamp - odata

I am using the ODATA version2. I want to filter all the employees who are having the DOB today through the Query. The dob field data is using the epoch(unix) timestamp format. For example "dateOfBirth": "/Date(488332700000)/"
I am trying something like:-
https://blah.com?$format=json&$expand=empInfo/personNav&$select=userId,empInfo/personNav/dateOfBirth&$filter=month(empInfo/personNav/dateOfBirth) eq int(utcNow('MM')) and day(empInfo/personNav/dateOfBirth) eq int(utcNow('dd'))

Related

What is the correct way to represent dates in a graph database (Neo4j)?

CREATE(:People{name: "Sally", date_of_birth:"12-04-1991"})
I'm confused as to how to find her current age. Is my way of representing a date wrong?
best way is to use the neo4j date / time format : https://neo4j.com/docs/cypher-manual/current/syntax/temporal/
But this should do it, given the date format that you use:
MATCH (p:People {name:"Sally"})
WITH p.date_of_birth AS date_of_birth ,date() AS now
// convert the stringDate into a date in the datetime format
WITH now,
date(
{year:toInteger(right(date_of_birth,4)),
month:toInteger(substring(date_of_birth,3,2)),
day: toInteger(left(date_of_birth,2))
}) AS date_of_birth
RETURN duration.between(dateOfBirth,now).years AS age

Rails 5 query using Pluck how do I format created_at to be date only?

I have this query which returns rows of created_at datetimes and a value, I would like the datetime to be just date. I can't work out how to use any of the datetime format options in this style of query. Any help appreciated.
#channels_counts_for_history_graph = Count.where(channel_id:
current_channel).pluck("counts.created_at", "counts.followers")
you can use date function from sql command
#channels_counts_for_history_graph = Count.where(channel_id:
current_channel).pluck("date(counts.created_at)", "counts.followers")

Sort by date in jsonb postgres

I have a model where the data is stored in json format in a jsonb column in postgres.
I want to sort the output by a data field using an activerecord query.
Model.all.order("json_data -> 'date'")
gives me an output but orders it alphabetically based on the date string.
Is there an easy way I can sort this as a date?
Note: The dates are in the following format:
"Fri, 24 Jun 2016 04:13:26 -0700"
If the date is in a sensible format Postgres will deal with this automatically.
Model.all.order("(json_data ->> 'date')::timestamp with time zone DESC")
or
Model.all.order("(json_data ->> 'date')::timestamptz DESC")
If your date field string is a little unorthodox, you can do the following
Model.all.order("to_timestamp(json_data->>'date','Dy, DD Mon YYYY HH24:MI:SS ') DESC")
Details here
Note the ->> there to output the string rather than the json object.
You can of course just create an extra column and store your information there as per #Uzbekjon's answer below.
Is there an easy way I can sort this as a date?
Not as part of the jsonb field, since JSON doesn't know anything about dates.
So, an easy alternative would be to store them as a separate table column.
If you really have to store them as an element of your json field, then I would suggest one of the two options:
Store your field as timestamp. Since, json fields in postgresql support numeric values and it could (potentially) optimize the sorting.
Store your date in ISO 8601 format string. It would sort correctly, even if it is a string.

Comparing datetime and date in a .where() on Rails

I'm working on an event system where admins can select events to feature and add promotional text. As they need to add additional text the featured events are in their own table and reference the event details.
I'm now trying to output featured events for each day in the next week. Simplified example:
day = DateTime.now.to_date
featured_events = #featured_events.where('event.start_datetime = ?', day)
The problem is that start_datetime is in datetime format and day is in date format so it always outputs nothing. Is it possible to compare these two values with .where()?
Thanks!
May be you're looking for this:
#featured_events.where('event.start_datetime > ? and event.start_datetime < ?', DateTime.now, 1.day.from_now.beginning_of_day)
You don't say what database you're using.
In PostgreSQL we'd truncate the datetime inside the DB query so the DBM can do the compare. On MySQL we'd use a function to convert the datetime to a date.

issue to query data filtered by Date from fusion table

I'm trying to write a small javascript code to query data filtered by date.
If I write the following sentence in my browser, I can get data :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883"
but if I write the same thing, except I want only data after a certain date :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883 WHERE Date > 2/29/12"
From the SQL-like API, https://developers.google.com/fusiontables/docs/developers_reference#Select, it should work
I get an error witch is "'internal_error', message:'Could not parse query'"
-Date is a DATETIME format in my fusion table.
-I've tried different format, but I can not get data.
What am I doing wrong?
Thank you very much for your help.
The Date value must be quoted and the format is MM/dd/yy so you must pad single digits with leading zeros.
I had success with:
select Date,Poids from 3049883 where Date >= '02/29/12'
Note: I did not test with gvizdata, just with the FT JSONP API

Resources