Function for previous month and present year

K

Kelly

I am looking for a relatively simple function that will give me the previous
month (March) and present year (2009). I know the basic formula to get the
present month and year

=Format(Date(),"mmmm yyyy")

But what do I add to make it give me the previous month? I'm a newbie in
case you didn't guess ;) so thanks for the patience!
 
D

Dirk Goldgar

Kelly said:
I am looking for a relatively simple function that will give me the
previous
month (March) and present year (2009). I know the basic formula to get the
present month and year

=Format(Date(),"mmmm yyyy")

But what do I add to make it give me the previous month? I'm a newbie in
case you didn't guess ;) so thanks for the patience!


The function expression

DateAdd("m", -1, Date())

Will give you the date one month before the current date, as a date/time
value. If you want to format that into a "month-name year" string as above,
use this:

=Format(DateAdd("m", -1, Date()), "mmmm yyyy")
 
K

Kelly

Thanks Dirk!
--
Kell needs help


Dirk Goldgar said:
The function expression

DateAdd("m", -1, Date())

Will give you the date one month before the current date, as a date/time
value. If you want to format that into a "month-name year" string as above,
use this:

=Format(DateAdd("m", -1, Date()), "mmmm yyyy")


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
A

apex77

This is great. What if I want to show a specific date and the current year? I
am trying to show an employee anniversary date, say 9/27/2000. I need the
field to show 9/27/(current year) in which the year changes every 12 Months.
What would that look like?
 
J

John Spencer

Given a date field named Anniversary, you could use this expression to get the
date where the year is the current year.

DateSerial(Year(Date()),Month([Anniversary]),Day([Anniversary]))

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
D

Douglas J. Steele

Are you saying you want to return the employee's anniversary date for the
current year?

DateSerial(Year(Date), Month(AnniversaryDate), Day(AnniversaryDate)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top