sql last day date function - sql

I have table like below, and I need to choose only the data for end day of each month. What proper query should I use ? I need also automated it, and with each subsequent montt the last day each month needs to be choose automaticly.
date_list
date=20201231
date=20211220
date=20201130
date=20201115
date=20201030
date=20201009
.
.
.
.
thanks,

Related

SPARQL search for first binding then stop

I have some stock data and I want to find the stock closing price two days following an event in which ?date was bound:
BIND (?date + \"P2D\"^^xsd:dayTimeDuration As ?doe)
?event <http://www.foo.com/stock/date> ?doe.
?event <http://www.foo.com/stock/close> ?close.
I can think of ways to increment the 2 but I want to stop as soon as I get a value for ?close. I want to increment "trading days" not really calendar days.
Is there an elegant way to keep incrementing "P2D" but then stop when I get a value?
I'd do something like SELECT the closing values for every day in the week (or whatever the longest gap in trading is) starting 2 calendar days after ?doe, then ORDER BY date, and LIMIT 1.
Elegant? Maybe not. But no stepping, and should be fairly fast.

Limiting data on monthly basis from start date to system date dynamically in Tibco spotfire

I've tried limiting data on monthly basis in spotfire and it's working fine.
Now I'm trying to do like getting the records from the current date to month start date.
For suppose if the current date is Sept 21, then i should get the records from Sept 21 to Sept-01(dynamically).
I have a property control to input the number of months.
The easiest way to do this is with Month and Year. For example, in your visualization:
Right Click > Properties > Data > Limit Data Using Expressions (Edit)
Then, use this expression:
Month([TheDate]) = Month(DateTimeNow()) and Year([TheDate]) = Year(DateTimeNow())
This will limit the data to only those rows with the current Year/Month combination in your data column. Just replace [TheDate] with whatever your date column name is.
In other places, you can wrap this in an IF statement if you'd like. It's redundant in this case, but sometimes helps with readability.
IF(Month([TheDate]) = Month(DateTimeNow()) and Year([TheDate]) = Year(DateTimeNow()),TRUE,FALSE)
#san - Adding to #scsimon answer. If you would like to precisely limit values between 1st of the current month to current date, you could add the below expression to 'Limit data using expression' section.
[Date]>=date(1&'-'&Month(DateTimeNow())&'-'&year(DateTimeNow())) and [Date]<=DateTimeNow()

Creating a DAX pattern that counts days between a date field and a month value on a chart's x-axis

I am struggling with a DAX pattern to allow me to plot an average duration value on a chart.
Here is the problem: My dataset has a field called dtOpened which is a date value describing when something started, and I want to be able to calculate the duration in days since that date.
I then want to be able to create an average duration since that date over a time period.
It is very easy to do when thinking about the value as it is now, but I want to be able to show a chart that describes what that average value would have been over various time periods on the x-axis (month/quarter/year).
The problem that I am facing is that if I create a calculated column to find the current age (NOW() - [dtOpened]), then it always uses the NOW() function - which is no use for historic time spans. Maybe I need a Measure for this, rather than a calculated column, but I cannot work out how to do it.
I have thought about using LASTDATE (rather than NOW) to work out what the last date would be in the filter context of any single month/quarter/year, but if the current month is only half way through, then it would probably need to consider today's date as the value from which to subtract the dtOpened value.
I would appreciate any help or pointers that you can give me!
It looks like you have a table (let's call it Cases) storing your cases with one record per case with fields like the following:
casename, dtOpened, OpenClosedFlag
You should create a date table with on record per day spanning your date range. The date table will have a month ending date field identifying the last day of the month (same for quarter & year). But this will be a disconnected date table. Don't create a relationship between the Date on the Date table and your case open date.
Then use iterative averagex to average the date differences.
Average Duration (days) :=
CALCULATE (
AVERAGEX ( Cases, MAX ( DateTable[Month Ending] ) - Cases[dtopened] ),
FILTER ( Cases, Cases[OpenClosedFlag] = "Open" ),
FILTER ( Cases, Cases[dtopened] <= MAX ( DateTable[Month Ending] ) )
)
Once you plot the measure against your Month you should see the average values represented correctly. You can do something similar for quarter & year.
You're a genius, Rory; Thanks.
In my example, I had a dtClosed field rather than an Opened/Closed flag, so there was one extra piece of filtering to do to test if the Case was closed at that point in time. So my measure ended up looking like this:
Average Duration:=CALCULATE(
AVERAGEX(CasesOnly, MAX(DT[LastDateM]) - CasesOnly[Owner Opened dtOnly]),
FILTER(CasesOnly, OR(ISBLANK(CasesOnly[Owner Resolution dtOnly]),
CasesOnly[Owner Resolution dtOnly] > MAX(DT[LastDateM]))),
FILTER(CasesOnly, CasesOnly[Owner Opened dtOnly] <= MAX(DT[LastDateM]))
)
And to get the chart, I plotted the DT[Date] field on the x-axis.
Thanks very much again.

Get current week from Access Date/Time Field in QT?

I need to get from Access DataBase all items with dates during the current week. The first day of week is Monday. But i can't write any DatePart query. Last attempt was:
qModel->setQuery("SELECT * FROM TimeTable WHERE (DatePart(\"ww\",[PlayDate])=DatePart(\"ww\",Date()));");
Qt returns -3010 mistake:"[Microsoft][Driver ODBC Microsoft Access] Too few parameters. Expected 1."
Also i know that other similar queries with Year() or #SomeDate# is working.
So how can i get current week items?
Use single quotes instead of double quotes in the SQL statement.
qModel->setQuery("SELECT * FROM TimeTable WHERE DatePart('ww',[PlayDate])=DatePart('ww',Date());");
Assuming that change eliminated the error, next add the option to indicate which is the first day of your weeks.
qModel->setQuery("SELECT * FROM TimeTable WHERE DatePart('ww',[PlayDate],2)=DatePart('ww',Date(),2);");

Sql query to find difference between date

I need a sql query which will find the difference between two dates . I have already tried the between clause query but It include the Starting date . But I need a query that exclude the start date . and so please provide me a different one.
You can use the DATEDIFF method
E.g:
SELECT DATEDIFF(SELECT DATE_ADD(start_date,INTERVAL 1 DAY),end_date);
If you want to exclude the start_date, or change the interval as per your requirements