using week number how to query in Azure Cosmos DB SQL - python-3.x

There is an iso format timestamp string in the Cosmos DB container.
{"timestamp": "2022-08-21T00:00:00"}
Using week number, how can I write the query so that entire week dates should pass in where clause
For week_number: 34 (or 2022-34) the date range will be "2022-08-21","2022-08-22", "2022-08-23","2022-08-24","2022-08-25","2022-08-26","2022-08-27"
One possible solution is to create this date list using code and then pass the start and end date using between clauses.
select * from c where c.timestamp between start_date and end_date
Is there any other way to do this in the Cosmos DB SQL query itself?

Related

Nodejs Service returning datetime instead of just date when trying to cast datetime field to date of a SQL Server Query

My database is SQL Server. I have the following sql query
SELECT RQI,RQIOver,PCI,PCIOver,PQI,PQIOver,SR,SROver,IRI,IRIOver,RUT,RUTOver,cast(DateCollected as date) as DateCollected,cast(DateCollectedOver as date) as DateCollectedOver from dbo.PF_Condition where SegmentId=12665
The result I am getting for DateCollected is just the date, which I need, when run it in SQL Management Studio. However when I put the same SQL query in a nodejs service which I created the result is not the same.
I needed to extract YYYY-MM-DD from datetime field DateCollected and DateCollectedOver as mentioned in the query above.
Can someone help me with it?
I made it work with the slice operator of javascript and sliced the date part only and displayed in the frontend where I need to. The results returned are of type string so the slice operator worked.
If someone can help why the cast function is not working in the sql query when I put it in the nodejs service it will be really helpful
After casting as DATE, you can then use the LEFT function to truncate the result to 10 characters:
LEFT(cast(DateCollected as date), 10) as DateCollected
which would return a string with the format 'YYYY-MM-DD'

Handling SQL date as string with node-mssql

I'm using node-mssql to get rows from a table that includes a date column (YYYY-MM-DD). I want to pass the date to a client application as a string in that same format. node-mssql is creating date objects, which I'm having to convert and slice at significant cost to get the format that I started with. sql.map.register(String, sql.Date) doesn't seem to work here (or I'm using it wrong). Is there a way to change how node-mssql handles the SQL date data type?
I'm having the same problem. sql.map.register is only for converting JS types to SQL types and I don't think there is any way to avoid SQL Date fields being converted into JS Date objects with node-mssql alone. I just changed my SQL query to convert to a formatted varchar instead of a Date type, e.g.: convert(varchar, birthday, 105) as dob.

DSE Solr date range query for String date 'yyyymmdd' & integer hour

I'm using Datastax Solr version 4.8. I've column with string values of date in 'yyyymmdd' format and another column with int values of hour. Now the requirement is to fetch all the records say from yyyymmdd - '20161110' to '20161130' and from hour 21 to 15.
Is there any way to get this search using DSE Solr?
I would suggest you to use a copy copy field with that string date as the source and a date field as the destination. Once your string date has been converted into an actual proper date you can query it like a normal date 'AND' the hour into the query. Hope it helps.
Finally I ended up adding timestamp column to get the date range query result.

cassandra query for list the data using timestamp

I am very new to Cassandra. I have one table with the following columns CustomerId, Timestamp, Action,ProductId. I need to select the CustomerId and from date - to date using time stamp.I dont know how to do this in cassandra any help will be appreciated.
First of all could you should remember that you should plan what queries will be executed in future and make table keys according to it.
If you have keys as (customerId, date) then your query can be for example:
SELECT * FROM products WHERE customerId= '1' AND date < 1453726670241 AND date > 1453723370048;
Please, see http://docs.datastax.com/en/latest-cql/cql/cql_using/useAboutCQL.html

How do I query for a specific day such as yesterday in Core Data?

In plain SQL (in my case: sqlite), I would be able to query for a specific date in a DATE column as follows:
SELECT * FROM table WHERE date(dateColumn) = '2015-01-01'
This works because the date() function cuts off the time part of the DATE value.
Can I do something similar with Predicates in Core Data? Or do I have to use something where I determine the start and end of that day and then look for dates between the two date values?

Resources