Date conversion in SSRS expression

Trying to get the last day of the previous month.  In SQL this works:
select dateadd(dd,-1,dateadd(mm,datediff(mm,0,getdate()),0))

When I try to use this in an SSRS expression, it doesn't work.  Here is my expression:
=CDate(dateAdd(DateInterval.Day,-1,dateAdd(DateInterval.Month,dateDiff(DateInterval.Month,0,Now()),0))).ToShortDateString

Any help on what I'm doing wrong???
Brenda WilkersonSR DBAAsked:
Who is Participating?
 
cyberkiwiCommented:
I think the first part should be cstr(month ..... but if that doesn't work, try this

dateadd("d",-1,dateserial(year(Today),month(Today),1))
0
 
cyberkiwiCommented:
try this instead

=dateadd("d",-1,CDate(cstr(day(today.now())) + "/1/" + cstr(year(today.now()))))
0
 
Brenda WilkersonSR DBAAuthor Commented:
2nd one worked and I got the date/time,
I tried to convert to shortdate string but it didn't convert:
=CDate(dateadd("d",-1,dateserial(year(Today),month(Today),1)).ToShortDateString)
0
 
Brenda WilkersonSR DBAAuthor Commented:
Never mind on the last comment, got it to work, just had ')' out of place.  Thanks for your help,  the following worked:   dateadd("d",-1,dateserial(year(Today),month(Today),1))
0
 
Brenda WilkersonSR DBAAuthor Commented:
Great help and quick as always, Thanks alot.....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.