Skip to content
Advertisement

Tag: date

How to round timestamp to nearest day with postgresql

How can I round a timestamp to the nearest day in postgresql. I have tried using function date_trunc(‘day’, d_date::timestamp) but I get that is always staying in the same day. Example 1: Example 2: (This one works fine) Answer You could add 12 hours to the timestamp and then do the truncation that you’re doing already. Something like…

How to read from the two same dates without input the time

I have a query like below. When I submit a date like the following patients.created_at BETWEEN ‘2018-05-22’ AND ‘2018-05-22’ it doesn’t return anything but if I enter BETWEEN ‘2018-05-22’ patients.created_at ‘AND’ 2018-05-23′ it returns a value. I think if I just input two of the same date without entering the time then the time will be 00:00:00 – 00:00:00. How

How to group by month and year?

I have a table PURCHASE with a date column PURCHASEDATE which is in DATE format. I’m trying to get the purchases grouped by month and year. To do so, I try with: I have also tryied with GROUP BY EXTRACT(MONTH FROM PURCHASEDATE), EXTRACT(YEAR FROM PURCHASEDATE) but neither worked. I’m rusty with SQL querys :S. EDIT Table cloumns Thanks ahead! Answer

SQL Server find rows approaching a service day and month

I have a table which lists equipment with an installation date. These items need to be serviced annually or every five years. So the rows have a service interval of 1 or 5. Something like: What I need to do is return a list of equipment two months before they are due for service For simplicity Let’s assume I have

Advertisement