Skip to content

Tag: datediff

How to use DateDIFF function in mysql table

I have a dataset in my library management system and I have used below query to get specific field only. now I need DATEDIFF function to get the date difference between today date and ReturnDate if there is no any receiveddate value.Further I dont need negative values as well. As an example if currdate()<ToBEReturnDate the value should be zero(mean that

How to use date_diff for two adjacent sessions using BigQuery?

I’m trying to calculate average hours between two adjacent sessions using the data from the following table: user_id event_timestamp session_num A 2021-04-16 10:00:00.000 UTC 1 A 2021-04-16 11:00:00.000 UTC 2 A 2021-04-16 13:00:00.000 UTC 3 A 2021-04-16 16:00:00.000 UTC 4 B 2021-04-16 12:00:00.000 UTC 1 B 2021-04-16 14:00:00.000 UTC 2 B 2021-04-16 19:00:00.000 UTC 3 C 2021-04-16 10:00:00.000 UTC 1

Sql – Calculate Inventory Days

I’m trying to calculate inventory day’s over time. I have an issue getting the actual amount of day’s in inventory for the last month. So as for the first row, the 9 days is correct. However the second row should show 34. Since I want to calculate the days between Inv_date and “today’s” Date. Let’s presume when I’m writing this,

Subtract today’s date with date column in SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question I have a column in SQL item_expired, this column stores data in the form of dates from other items. What I want to ask, how

Data aggregation by sliding time periods

[Query and question edited and fixed thanks to comments from @Gordon Linoff and @shawnt00] I recently inherited a SQL query that calculates the number of some events in time windows of 30 days from a log database. It uses a CTE (Common Table Expression) to generate the 30 days ranges since ‘2019-01-01’ to now. And then it counts the cases