date-arithmetic

how to calculate only days between two dates in postgres sql query .

自闭症网瘾萝莉.ら 提交于 2019-12-11 06:27:13
问题 Suppose I have given two dates, if difference is one month then it should be display as 30 days.Even months also need to convert into days I have tried with age( date,now()::timestamp without time zone) but it is giving months-dates-years format. ex: 10 mons 24 days 13:57:40.5265.But I need following way. For example if two months difference is there then I need output as 60 days. 回答1: Don't use the age() function for date/time arithmetic. It only returns "symbolic" results (which are good

Manipulating last two rows if there's data based on a Cut date

我的未来我决定 提交于 2019-12-11 06:06:56
问题 This question is a slightly varied version of this one... Now I'm using Measures instead of Calculated columns and the date is static instead of having it based on a dropdown list. Here's the Power BI test .pbix file: https://drive.google.com/open?id=1OG7keqhdvDUDYkFQFMHyxcpi9Zi6Pn3d This printscreen describes what I'm trying to accomplish: Basically the date in P6 Update table is used as a cut date and will be fixed\static. It's imported from an Excel sheet where the user can customize it

Oracle UNPIVOT and SYSDATE giving weird results

♀尐吖头ヾ 提交于 2019-12-11 02:44:34
问题 I am trying to transpose columns to rows using query similar to the following... WITH query AS ( SELECT SYSDATE AS SomeDate, 'One' AS One, 'Two' AS Two, 'Three' AS Three, 'Four' AS Four, 'Five' AS Five FROM dual ), up_query AS ( SELECT * FROM query UNPIVOT ( NUM FOR DUMMY IN ( One AS 'One', Two AS 'Two', Three AS 'Three', Four AS 'Four', Five AS 'Five' ) ) ) SELECT SYSDATE, b.* FROM up_query b; I was expecting SomeDate to reflect SYSDATE for the resulting rows... But this is the result I am

Simple Java Date Calculations

孤者浪人 提交于 2019-12-10 13:26:25
问题 I would like to do simple date calculations in Java. For example, compute the difference in days between to dates (having a 0 time component). Of course you could do a simple substraction of milliseconds, divided by the number of milliseconds per day, which works fine - until daylight saving times enter the scene. I am conscious that different interpretations of the "difference in days" are possible, in particuliar, whether one should take into account the time component or not. Let us assume

How do I exclude weekends in SQL?

白昼怎懂夜的黑 提交于 2019-12-10 09:44:45
问题 I have a date column SLA_Date in the Orders table. My SLA_Date should exclude weekends (Saturday & Sunday). Data for weekdays should be shown alone. How do I do that in SQL? 回答1: You just need to add the following filter : WHERE TO_CHAR(date_column, 'DY','NLS_DATE_LANGUAGE=AMERICAN') NOT IN ('SAT', 'SUN') Your query would look like: SELECT SLA_Date FROM orders WHERE TO_CHAR(SLA_Date, 'DY','NLS_DATE_LANGUAGE=AMERICAN') NOT IN ('SAT', 'SUN') For example(the WITH clause is only to build a test

jQuery: pass string variable to date object

血红的双手。 提交于 2019-12-10 01:56:44
问题 I have a page with a number of variables that contain a date in string format (yyyy-mm-dd) which originates from using moment.js. Is there a way I can pass such a variable to a Javascript date object resp. to convert it to a Javascript date object ? I am not interested in the time so as long as I can get the date converted to a date object that would be great. I tried the following but this doesn't work and I couldn't find a way using moment.js: var newVar = new Date(dateVar); Many thanks for

find the elapsed time between two dates in oracle sql

旧时模样 提交于 2019-12-09 09:44:32
问题 i need to find the difference between the time in the format hh:mm:ss select msglog.id,max(msglog.timestamp) enddate, min(msglog.timestamp) startdate, enddate - startdate from MESSAGELOG msglog group by id In the abovequery msglog.timestamp is of type DATE. How can I get the elapsed time or diff between the time in the correct format in oracle? 回答1: When you subtract two DATE values like enddate - startdate you get the difference in days with decimal accuracy, so for example 1.5 would mean 1

T-SQL to trim a datetime to the nearest date?

旧时模样 提交于 2019-12-08 14:40:04
问题 Duplicate of What's the BEST way to remove the time portion of a datetime value (SQL Server)? I have a column that tracks when things are created using a datetime, but I'd like to generate a report that groups them by day, so I need a way of nulling out the time component of a datetime column. How do I do this? 回答1: One way is to change getdate() to your column name, select dateadd(dd, datediff(dd, 0, getdate())+0, 0) 回答2: Why not convert straight to date: select convert(date, getdate()) This

convert decimal to time 6.80 =7.20 hrs in SQL [duplicate]

折月煮酒 提交于 2019-12-08 06:47:52
问题 This question already has answers here : Convert decimal time to hours and minutes (4 answers) Closed 5 years ago . Please help me to do this decimal 6.80 should equal to 7.20 hours DECLARE @R1 decimal(4,2); DECLARE @R2 decimal(4,2); declare @Type1 decimal(4,2); declare @Type2 decimal(4,2); DECLARE @R1Time decimal(4,2); DECLARE @R2Time decimal(4,2); SET @R1=2.5 SET @R2=3.5 SET @Type1=17; SET @Type2=7; SET @R1Time=(FORMAT((ISNULL(60.0/NULLIF(@R1,0),0)),'N2')) SET @R2Time=(FORMAT((ISNULL(60.0

Oracle (10g) equivalent of DATEADD(weekday, -3, GETDATE())

人盡茶涼 提交于 2019-12-08 05:12:55
问题 I'm looking for the Oracle (10g) equivalent of: DATEADD(weekday, -3, GETDATE()) from T-SQL (SQL Server) . This subtracts 3 weekdays from the current date. I'm not concerned about holidays or anything like that (and I can truncate the time part off myself). Just excluding weekends is fine. 回答1: It looks like you need to create a UDF. CREATE OR REPLACE FUNCTION business_date (start_date DATE, days2add NUMBER) RETURN DATE IS Counter NATURAL := 0; CurDate DATE := start_date; DayNum POSITIVE;