Month to date query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have built a database which queries Daily, mtd, and ytd totals, I cannot
figure out how to get the mtd or ytd totals when it is the end of the month,
since Month(Now()) returns the present month. If it is the first of the
month, it should come back as last month's total, not the present month, Any
help appreciated

Thx
Eric
 
You can get the last day of previous month using the expression:

DateSerial(Year(Date()), Month(Date()), 0)

You can the use the Month() function on the above expression to get last
month.

If you want to restrict the data using "BETWEEN ... AND ...", the first day
of last month is:

DateSerial(Year(Date()), Month(Date()) - 1, 1)
 
Check these two possibilities:

- Month of yesterday: Month(DateAdd("d",-1,Date()))
- Month of today, but if 1st month day, then month of yesterday:
IIf(Day(Date())<>1,Month(Date()),Month(DateAdd("d",-1,Date())))

Hope being helpful


Tonín
Spain
 
Back
Top