Wednesday, March 21, 2012

Need some help with expressions

I'm pretty much a rookie with this so I'm wondering if someone might
be able to point me in the right direction here..
Here's what I'm using now:
=MonthName(Month(NOW())-1) & ", " & YEAR(NOW()) which displays 'April,
2007'
What I'm trying to do is provide the month,year of the previous
month. For example, we're in May now, and the formula above is
working but once we get to Jan of 2008, the code above will return
December, "2008" instead of December, 2007. I'm sure there's gotta
be an easy way I'm just missing here.. Anyone have any suggestions?
Thanks in advance!Use DateAdd("m", -1, Now()) but you must use it on both parts as your code
will give you December 2007 for January 2007
=MonthName(DateAdd("m", -1, Now())) & ", " & Year(DateAdd("m", -1, Now()))
There is also a great article on how to do date stuff in T-SQL, that might
help with other ideas.
http://www.databasejournal.com/features/mssql/article.php/3076421
Reeves
"tek_1975@.yahoo.com" wrote:
> I'm pretty much a rookie with this so I'm wondering if someone might
> be able to point me in the right direction here..
> Here's what I'm using now:
> =MonthName(Month(NOW())-1) & ", " & YEAR(NOW()) which displays 'April,
> 2007'
> What I'm trying to do is provide the month,year of the previous
> month. For example, we're in May now, and the formula above is
> working but once we get to Jan of 2008, the code above will return
> December, "2008" instead of December, 2007. I'm sure there's gotta
> be an easy way I'm just missing here.. Anyone have any suggestions?
> Thanks in advance!
>|||Better: Format(DateAdd("m", -1, Now()), "MMMM YYYY")
"tek_1975@.yahoo.com" wrote:
> I'm pretty much a rookie with this so I'm wondering if someone might
> be able to point me in the right direction here..
> Here's what I'm using now:
> =MonthName(Month(NOW())-1) & ", " & YEAR(NOW()) which displays 'April,
> 2007'
> What I'm trying to do is provide the month,year of the previous
> month. For example, we're in May now, and the formula above is
> working but once we get to Jan of 2008, the code above will return
> December, "2008" instead of December, 2007. I'm sure there's gotta
> be an easy way I'm just missing here.. Anyone have any suggestions?
> Thanks in advance!
>|||On May 22, 1:57 pm, Reeves Smith
<ReevesSm...@.discussions.microsoft.com> wrote:
> Better: Format(DateAdd("m", -1, Now()), "MMMM YYYY")
>
> "tek_1...@.yahoo.com" wrote:
> > I'm pretty much a rookie with this so I'm wondering if someone might
> > be able to point me in the right direction here..
> > Here's what I'm using now:
> > =MonthName(Month(NOW())-1) & ", " & YEAR(NOW()) which displays 'April,
> > 2007'
> > What I'm trying to do is provide the month,year of the previous
> > month. For example, we're in May now, and the formula above is
> > working but once we get to Jan of 2008, the code above will return
> > December, "2008" instead of December, 2007. I'm sure there's gotta
> > be an easy way I'm just missing here.. Anyone have any suggestions?
> > Thanks in advance!- Hide quoted text -
> - Show quoted text -
Awesome.. Thanks a ton Reeves.. that definitely got me going on the
right track..
Here's what I ended up using..
SELECT SUBSTRING(CONVERT(VARCHAR(30), @.mydate, 113), 4, 8)
Then I'm going to use a report parameter to return the last day
(@.mydate) of the previous month and then convert it using the line
above. I'm sure there might be more elegant ways of doing this...but
it's working!! Thanks again..|||On May 22, 1:57 pm, Reeves Smith
<ReevesSm...@.discussions.microsoft.com> wrote:
> Better: Format(DateAdd("m", -1, Now()), "MMMM YYYY")
>
> "tek_1...@.yahoo.com" wrote:
> > I'm pretty much a rookie with this so I'm wondering if someone might
> > be able to point me in the right direction here..
> > Here's what I'm using now:
> > =MonthName(Month(NOW())-1) & ", " & YEAR(NOW()) which displays 'April,
> > 2007'
> > What I'm trying to do is provide the month,year of the previous
> > month. For example, we're in May now, and the formula above is
> > working but once we get to Jan of 2008, the code above will return
> > December, "2008" instead of December, 2007. I'm sure there's gotta
> > be an easy way I'm just missing here.. Anyone have any suggestions?
> > Thanks in advance!- Hide quoted text -
> - Show quoted text -
Awesome.. Thanks a ton Reeves.. that definitely got me going on the
right track..
Here's what I ended up using..
SELECT SUBSTRING(CONVERT(VARCHAR(30), @.mydate, 113), 4, 8)
Then I'm going to use a report parameter to return the last day
(@.mydate) of the previous month and then convert it using the line
above. I'm sure there might be more elegant ways of doing this...but
it's working!! Thanks again..

No comments:

Post a Comment