Getting previous month name

Agom008

Registered User.
Local time
Tomorrow, 07:34
Joined
Aug 29, 2014
Messages
27
Hi,

So I want the Month name for previous month which I have tried to do like this:

Code:
[SIZE=3][FONT=Calibri]=Format(Month((DateSerial(Year(Now()),Month(Now())-1,”mmmm”)))[/FONT][/SIZE]

Which gives me an error, I can get the current month name but I want to get the previous months name dynamically, so I don't want to do it like Date()-30.

Can someone help me please?


Thanks
 
You probably get the error because you haven't supplied all 3 arguments of the DateSerial() function.
 
Hi,

Thanks for your response, but it gives me the right date when I do this:

Code:
[FONT=Calibri]DateSerial(Year(Now()),Month(Now())-1)[/FONT]

How is that possible?
 
Hi,

Thanks for your response, but it gives me the right date when I do this:

Code:
[FONT=Calibri]DateSerial(Year(Now()),Month(Now())-1)[/FONT]

How is that possible?

It isn't. DateSerial has three mandatory arguments.

BTW Since you are not interested in the time use Date() instead of Now().

Also you only want the name for the previous month and the months have always been in the same order, there is no point calculating the year.

This will do the job
Code:
Format(DateSerial(0,Month(Date()),0),"mmmm")

The zero day argument in DateSerial gives the last day of the previous month.
 
oh my bad, I actually did this:

Code:
DateSerial(Year(Date()),Month(Date())-1,1)

which worked, and thanks so much, it all worked beautifully.

I have one more question, it isn't really regarding this, but is it possible to write a query using another info from another query and info from another table?
 
I have one more question, it isn't really regarding this, but is it possible to write a query using another info from another query and info from another table?

Yes. Saved queries can be incorporated as the source of another query just like a table.
 
There's also the VBA.MonthName() function . . .
Code:
? MonthName(Month(DateAdd("m", -1, Date)))
 

Users who are viewing this thread

Back
Top Bottom