Is 23:59:59.999 end of day? - datetime

In my project involving dates calculation I am wondering what is really end of day coming from a previous question:
extract date ranges grouped by day from time intervals
Is 23:59:59:999 end of day or is it 24:00:00:000?
Thanks.

In .Net the property Hour is between 0 to 23 so I think 23:59:59:999 is the correct answer

Related

How to make a Line Chart with multiple Series where one series has null values

I have a line chart that has 3 series - the first shows cumulative sales for last week - the next shows the daily sales for this week and the next shows cumulative sales for this week.
This shows the days of the week at the bottom.
Last weeks cumulative sales show fine as there is data for each day of the week.
For this week's daily and cumulative sales I don't want a point drawn if the day hasn't happened yet.
I loop through the days of the week and if the day hasn't happened yet I want to assign the value to null instead of 0 and I don't want the line to show anything for these series if the day hasn't happened yet.
Does anyone have advice on this point?
After much looking I found how to do this. It was very easy and described in the below documentation from shieldui.com:
Example using null in dataSeries
I had earlier tried all manner of sending empty strings, null value strings and in the end it was as simple as setting that data member to null like this and shieldui handled it correctly:
dailyincome = null;

How to show time difference of hours which are greater than 24 hours?

I'm facing difficulties to show the time time difference in hours where hours are greater than 24.
Right now I'm using the following in iReport
(new SimpleDateFormat("dd':'HH':'mm':'ss")).format(new Date($V{avgDuration}.longValue()*1000))
where $V{avgDuration} is a variable in jrxml file which is the average time difference between two dates in seconds. Here it shows the 1 day 1 hour but I want it to be 25 hour. What should I do?
I've solved the problem using PeriodFormatterBuilder. But for this, I need to use joda-time library.
In the expression editor of the text box in jrxml file, just wrote the following:
new org.joda.time.format.PeriodFormatterBuilder()
.printZeroAlways()
.minimumPrintedDigits(2)
.appendHours().appendSeparator(":")
.appendMinutes().appendSeparator(":")
.appendSeconds()
.toFormatter()
.print(new org.joda.time.Period(
$V{avgDuration}.longValue()*1000))

how to get the number of months and exceed days

here is my sample is this correct?
number of months=nms
days=30 days only
sample: nms=30 days count from the date hired
is this correct?
If you want to get exact month between two date. You have to get difference of them. You can use DateDiff function in Dot Net.

How do I get the last day on the month using SQL Reporting Services

In SQL Server Reporting Services, how would I calculate the last day of the current month?
Here is the answer I came up with
=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(1).AddDays(-1)
As it took me a while to Figure this out, and JC's answer was the simplest to modify and had a good logical structure. I expanded it Slightly for others searching for answers on this topic.
I have found normally you don't just want the Last Day of a month / year you also want the first day of the month / year. So here they are the full lines to calculate just that. wtih the SQl version there also.
First Day of Current month
SSRS=Today.AddDays(1-Today.Day)
SQL=SELECT DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,getdate()),0))
Last day of Current Month
SSRS=Today.AddDays(1-Today.Day).AddMonths(1).AddDays(-1)
SQL=SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
First Day of Current year
SSRS=Today.AddMonths(1-Today.month).AddDays(1-Today.day)
SQL=SELECT DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)
Last Day of Current Year
SSRS=Today.AddDays(1-Today.Day).AddMonths(13-today.month).AddDays(-1)
SQL=SELECT DATEADD(dd,-1,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,getdate())+1,0)))
I hope this helps somone.
I know you've found your own answer, but I'd suggest this alternative:
=Today.AddDays(1-Today.Day).AddMonths(1).AddDays(-1)
It's a little easier to read, in my opinion, and might have slightly better performance (though most likely unnoticeable)
And, of course, if you wanted to pad out that date to 23:59:59, as is often necessary, just modify slightly:
=Today.AddDays(1-Today.Day).AddMonths(1).AddSeconds(-1)
From the blog of a Microsoft SQL Team member:
-- returns the last day of the current month.
select dbo.Date(year(getdate()), month(getdate())+1,0)
http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx
Hope this helps!
--Dubs
You may try this expression, Just replace now with your date field.
=DateSerial(Year(Now), Month(Now), 1)
Hope this helps.
Regards
There is an even easier way as in the marked answer:
=DateSerial(Year(Now()), Month(Now())+1, 0)
Since DateSerial() accepts integers as parameters one does not have to use AddMonths() and AddDays(). As in the example an instant calculation inside DateSerial() is possible.
Furthermore day 1 is the first day of the month while the first day minus one day is the last day of the month before (1-1=0). So the example will return the date of the last day of the current month.
you can use an assembly for doing this work by adding it as a reference.

Interval of one month back not working on the 31st?

Essentially, I have a query that is responsible for fetching all records (with specific filters) within the last month. I'm using Oracle's interval keyword and all was working great until today (December 31st, 2009). The code I'm using is
select (sysdate - interval '1' month) from dual
and the error I get it
ORA-01839: date not valid for month specified
How can I use the interval keyword to be compatible with any date? Or if anyone has a better way of approaching the issue, I'm all ears.
Thank you.
try
select add_months(sysdate,-1) from dual
Being pedantic...
The requirements are not quite specified perfectly unambiguously. What does the business mean by "within the last month"? Most people would take that to mean "within the current calendar month" in which case I'd use:
TRUNC(SYSDATE,'MM')
Otherwise, perhaps they want an arbitrary period of 1 month prior to the current date - but then how do you define that? As you've found, INTERVAL '1' MONTH simply subtracts one from the month portion of the date - e.g. 15-JAN-2009 - INTERVAL '1' MONTH returns 15-DEC-1999. For some dates, this results in an invalid date because not all months have the same number of days.
ADD_MONTHS resolves this by returning the last day in the month, e.g. ADD_MONTHS(31-DEC-2009,-1) returns 30-NOV-2009.
Another possibility is that the business actually wants to use an average month period - e.g. 365/12 which is approximately 30.4. They might want you to use SYSDATE-30, although of course twelve iterations of this will only cover 360 days of the year.

Resources