How do I get the first and last day of the previous year in SSRS for default dates
tired wth DATEADD function but getting an error
You can use DATESERIAL() to do this easily
DateSerial just take 3 integer values (year, month, day) to return a date.
First day
=DateSerial( year(today()) - 1, 1, 1)
Last Day
=DateSerial( year(today()) - 1, 12, 31)
You don't show what you tried so we can't explain what you are doing wrong.
If I needed to get the 1st day of the previous year, I would take the current year, subtract the number of days from 1 and then subtract a year.
With DATEADD, the first day of last would be:
=DATEADD("yy", 1, DATEADD("d", 1 - DATEPART("dy", TODAY), TODAY))
While the last day is actually simpler:
=DATEADD("d", 0 - DATEPART("dy", TODAY), TODAY)
I need to construct a data parameter in SSRS 2008 where if the current week number is 1 then I use the first day of the previous month and if not then I use the current day.
I.e. today is week 4 therefore would utilize today's date
If today was march 2, then the week would be week 1 and I would utilize the first of the previous month, feb 1
note: weeks must follow calendar weeks.
Thanks in advance for your assistance
You can set the parameter default using the following expression:
=IIf(Day(Today()) <=7
and DatePart(DateInterval.WeekDay, Today(), FirstDayOfWeek.Monday)
>= DatePart(DateInterval.WeekDay, DateSerial(Year(Today()), Month(Today()), 1), FirstDayOfWeek.Monday)
, DateAdd(DateInterval.Month, -1, DateSerial(Year(Today()), Month(Today()), 1))
, Today())
So:
If today is one of the first seven days of the month, and the day of the week number is >= the day of the week of the first of the month
=> First week, so use the first day of the previous month
=> Else use the current date.
Here I need a function in MySQL where it returns
Dates
Starting date of previous month
Last date of current month.
starting date of previous month
select date_format(curdate() - interval 1 month,'%Y-%m-01 00:00:00')
last date of current month
select date_format(last_day(curdate()),'%Y-%m-%d 23:59:59')
You would use NOW() to get the current date and time. MONTH() to get the current month. And using that value, you can get the previous month and the next month. see http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
Last day of current month:
select last_day(now())
Starting date of previous month:
select adddate(subdate(last_day(now()), interval 2 month), 1)
In SQL Server Reporting Services; How can I calculate the first and last day of the previous month?
I know I can use the expression below to get the last day of the current month, but I'm stuck when trying to find the first and last of the previous month.
=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(1).AddDays(-1)
Just a guess based on your code working.
--previous month last
=DateSerial(Year(Now()), Month(Now()), "1").AddDays(-1)
--previous month first
=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(-1)
First day of this month:
=dateadd("m",0,dateserial(year(Today),month(Today),1))
Last day of this month:
=dateadd("m",1,dateserial(year(Today),month(Today),0))
First day of last month:
=dateadd("m",-1,dateserial(year(Today),month(Today),1))
First day of next month:
=dateadd("m",1,dateserial(year(Today),month(Today),1))
Last day of last month:
=dateadd("m",0,dateserial(year(Today),month(Today),0))
Last day of next month:
=dateadd("m",2,dateserial(year(Today),month(Today),0))
For current month
=DateSerial(Year(Parameters!ParameterName.Value), Month(Parameters!ParameterName.Value), "1").AddMonths(1).AddDays(-1)
Previous month last day:
=DateSerial(Year(Now()), Month(Now()), "1").AddDays(-1)
Previous month first day:
=DateSerial(Year(Parameters!ParameterName.Value), Month(Parameters!ParameterName.Value), "1").AddMonths(-1)
Previous month last date:
=DateAdd("d",-(Day(today)), Today)
First of previous month:
=DateAdd("m",-1,DateAdd("d",1-(Day(Today)), Today))
=DateSerial(Year(Now), Month(Now), 1) for first day of the month
and
=DateSerial(Year(Now), Month(Now)+1, 0) for the last day of the month.
http://www.answermysearches.com/ssrs-how-to-set-a-default-parameter-to-the-first-day-of-the-month/2167/
Using Native VB Functions
First Day of Previous Month
=DateAdd("m", -1, DateSerial(Year(Today()), Month(Today()), 1))
Last Day of Previous Month
=DateAdd("d", -1, DateSerial(Year(Today()), Month(Today()), 1))
I was able to accomplish this, and show it in mm/dd format by using:
=Format(DateAdd("D", -1, (DateAdd("M", 1, yourdate.value))), "MM/dd")
=DateSerial(Year(Now), Month(Now), 1)
I have the week number and year as separate fields in MySQL, how do I compute the last day of the week(Sunday) in the given year?
SELECT STR_TO_DATE('201038 Sunday', '%X%V %W');
This gives you sunday of the current week (38/2010). I used sunday because the "last day" is not consistend. sometimes its sunday, sometimes saturday (week starts on monday)...