Friday, February 24, 2012

date expression for param - start of current month

I have a report that I want to run for the current month. I have two
params, datestart and dateend and am looking for an expression to use
that will calculate the start of the current month. I have been
playing with datediff and dateadd but can't figure it out!
Please helpUse the datepart function to get the current month and year, then reconstruct
a date using those parts and just use '1' as the day... something like this:
firstday = datepart(mm, getdate()) + '/01/' + datepart(yyyy, getdate())
uhm... pretty sure you have to do some casting in there because datepart
returns integers... but otherwise it should work to get the actual first of
the month.
"gavinator@.nospam.nospam" wrote:
> I have a report that I want to run for the current month. I have two
> params, datestart and dateend and am looking for an expression to use
> that will calculate the start of the current month. I have been
> playing with datediff and dateadd but can't figure it out!
> Please help
>|||One of the easiest ways to accomplish this is
Date() - Day(Date()) + 1
and the easiest way to get the last day of the
previous month is to exclude the "+ 1" part.
GeoSynch
"Timm" <Timm@.discussions.microsoft.com> wrote in message
news:EEEEAAEB-B288-4F23-B67E-6DCEA4C35C32@.microsoft.com...
> Use the datepart function to get the current month and year, then reconstruct
> a date using those parts and just use '1' as the day... something like this:
> firstday = datepart(mm, getdate()) + '/01/' + datepart(yyyy, getdate())
> uhm... pretty sure you have to do some casting in there because datepart
> returns integers... but otherwise it should work to get the actual first of
> the month.
> "gavinator@.nospam.nospam" wrote:
>> I have a report that I want to run for the current month. I have two
>> params, datestart and dateend and am looking for an expression to use
>> that will calculate the start of the current month. I have been
>> playing with datediff and dateadd but can't figure it out!
>> Please help

No comments:

Post a Comment