How to add time to last Sunday ssrs expression? - reporting-services

How to add the time 23:59:59 pm to the following expression:
=DateAdd(DateInterval.Day, 1-WeekDay(Today), Today)
I've tried adding the time
=DateAdd(DateInterval.Day, 1-WeekDay(Today)+ "23:59:59", Today)
The expression is returning me the last Sunday day but I need to add the time somehow

I think it's easier to subtract a second from tomorrow.
=TODAY.AddDays(1 - TODAY.DayOfWeek).AddSeconds(-1)
I think if you want to use DATEADD, you'd need one for each interval (Hour, minute and second).

Related

Week To Date Based Off Current Date

I am looking for an expression that will allow to me find the date of Monday of the week of my Date Field, to be used in a filter for a tablix.
Example, my date field today is 22/01/2019. I would like an expression that will return 21/01/2019. If the date was 26/01/2019, it should still return 21/01/2019.
For next week 31/01/2019 would return 28/01/2019.
Week starting Monday going to Sunday.
If its also possible for a similiar expression but to find the beginning of the month as well?
Is that possible?
Many thanks
To get the date of last Monday that occurred you can use something like
=Today.AddDays(1-WeekDay(Today(),FirstDayOfWeek.Monday))
and for the first of the month its just
=DateSerial(Year(Today()), Month(Today()), 1)
Both the above are based on the today() function, if you need them based on a date parameter, then the expression is a little different but your question stated "today".
monday of the week use the following expression:
DateAdd("d",DatePart(DateInterval.WeekDay,Fields!myDatefield.Value,0,0)+1,Fields!myDatefield.Value)
first day of the month use the following expression:
=DateAdd("d",-(Day(Fields!myDatefield.Value)-1), Fields!myDatefield.Value)

Netezza What is the best way to get the first day of the month for a date?

Select to_date(to_char(date_part('year',current_date),'0000') || trim(to_char(date_part('month',current_date),'00')) || '01','YYYYMMDD')
So far, this is the best I can come up with.
I am also unable to find a comprehensive language reference for Netezza SQL that has all functions in it, so please include a source in your answer.
Use date_trunc('month', current_ date), which is documented here.
Start with the date, for what I needed today, was using current date/month. Then find the last day of the current month. That's the outer shell for the first day as a systematic output:
start with the current date
use add_months (-1) to subtract a month;
find the last day of the previous month;
add 1 day.
I then decided to test out on February (leap year and normal), finding the first from the first, and then adding in finding the first of the next month. Also checked looking at a month ago from a month ending 31st and 30th. I think this should be flexible.
select current_date,
last_day(add_months(current_date,-1))+1 as firstdt_currmos,
last_day(current_date) as lastdt_currmos
;
select last_day(add_months('02-29-2016',-1))+1 as firstdt_febleap,
last_day(add_months('02-28-2019',-1))+1 as firstdt_febnorm,
last_day(add_months('07-01-2019',-1))+1 as firstdt_first,
last_day(add_months(current_date,-1))+1 as firstdt_currmos,
last_day(current_date)+1 as firstdt_nextmos,
last_day(add_months('07-31-2019',-1))+1 as firstdt_mos31st,
date(add_months('07-31-2019',-1)) as mosago_31st,
date(add_months('06-30-2019',-1)) as mosago_30th
;

SSRS Date Parameter default to last 30 days with Time

Please could someone help me in getting the below issue sorted?
I am looking for a default Date Parameter (Start Date) to be Last 30 days from Today along with the Time e.g 30 days from now is 24/05/2016 but would like to include Time as well
24/05/2016 07:00:00
I have an expression which only give me Last 30 days date Expression i have is =DateAdd("d",-29,Today())
Regards
Try:
=Now.AddDays(-30)
UPDATE: Default time
=Today.AddDays(-30).AddHours(7)
Let me know if this helps.
SSRS Expression to get 30 days back from today using DateAdd function:
=DateAdd(DateInterval.Day, -30,Today())

SSRS - Report Builder 3.0 - This Day Last Year

I'm trying to get a Today vs This Day Last Year Comparison Report sorted.
I set a 'From' and 'To' date based on a 'Preset' parameter.
So if it is set to 'This Week' it sets the start date to Monday and the end date to Sunday.
What I want now is a Today vs This Day Last Year. So for example, if i were to do it for today, I would get 09/04/2015 vs 10/04/2014. So as today is Thursday, I want the nearest Thursday from 09/04/2014.
Also want the same for 'Yesterday'. So 08/04/2015 vs 09/04/2014
Is there a way to do this in either the Parameters SSRS expression, or within the custom 'Code' section?
To get this day last year, you can just subtract 52 weeks from today. Try this expression: =DateAdd("ww",-52,Today()). Likewise you can subtract 1 day from today to get yesterday: =DateAdd("d",-1,Today()).

Get the week number from a given date

Examples:
'DD/MM/YYYY
"1/1/2009" should give `1`
"31/1/2009" should give `5`
"1/2/2009" should also give `5`
Format("1/2/2009", "ww") returns 6.
So, how can I get the correct result?
It's doing two things here which don't match your expectations, I think:
Assuming you want the week with Jan 1 in as week 1, and using Sunday as first day of the week
So it has week 1 running from Sunday 28th December 2008 to Saturday 3rd Jan 2009.
Week 6 would begin on Sunday 1st Feb by this method.
The ISO standard is for week 1 to be the one containing 4 days of January, or the first Thursday of the year (different ways of expressing the same thing).
You can specify this method of calculation and the first day of the week:
Format(SomeDate,"ww",vbMonday,vbFirstFourDays)
see here for syntax:
https://support.office.com/en-US/article/Format-Function-6F29D87B-8761-408D-81D3-63B9CD842530
Regardless of the day of the week your week starts on, you need to pass unambiguous date values. "31/1/2009" can only be one date (Jan 31st), but "1/2/2009" could be Jan. 2 (US style) or Feb. 1st (everybody else who has more sense that we USAns).
In this case, I'd use DateSerial() to make sure the date is not misinterpreted:
Format(DateSerial(2009,2,1), "ww", vbMonday)
While this is not causing your problem, because Access helpfully utilizes your system's localized date settings, I think it's something you should do anyway. You certainly are forced to do so in SQL in Access, so I don't think it's a bad habit in code and expressions.
This might work: Format(YourDate, "ww",vbMonday)
"Correct result" depends on the locale. Maybe VBA will let you pick a calendar-system, otherwise you're pretty much out of luck.
Note that First-Day-On-xxDay isn't your only problem. There is also variation on what a complete week is so Week 1 in one system could be Week 53 of the previous year in another system.
So test thoroughly and don't be seduced to "correct by 1".
There is a whole standard for week numbers: ISO-8601
http://en.wikipedia.org/wiki/ISO_8601#Week_dates
I had the same problem.
It showed week 53 and week 1, yet days in week 53 and week 1 are all in week 1
I first tried changing the date format in the Access Query to this:
OrderWeek: Format([OrderDate],"yyyy-ww",1,3) <-- But it did not do the trick.
You get dates like 2014-52 for week 52 and 2015-52 where it was week 1 before.
Also the sorting was not how I liked. It sorted the data as 2014-1, 2014-11, 2014-2 etc. I want it to show as 2014-01, 2014-02 .. 2014-11 etc.
So here is the new code to display both the year and the week correctly in an Access Query:
ActualWeek: IIf(DatePart("ww",[SomeDate])=53,DatePart("yyyy",[SomeDate])+1,DatePart("yyyy",[SomeDate])) & "-" & IIf(DatePart("ww",[SomeDate])=53,"01",IIf(DatePart("ww",[SomeDate])<10,"0" & DatePart("ww",[SomeDate]),DatePart("ww",[SomeDate])))
This now shows any days from week 53 as being part of week 1
If sunday is the first day of the week (as it is in some locales) then 6 is the correct weeknumber for "1/2/2009" (february 1. 2009)
In terms of the sorting, I had the same issue and used this code to resolve it:
IIf(Format([SomeDate],"ww")<10,Format([SomeDate],"yyyy-") & "0" & Format([SomeDate],"ww"),Format([SomeDate],"yyyy-ww"))
If the week number is less than 10, add a zero, else leave it as is.
Now the sorting is fine. Hope this helps somebody.