Search code examples
sqlms-accessms-access-2010ms-access-2007criteria

MS-Access criteria: get 2 digits for months


This is the query that I have, which is months in two digits. enter image description here

My goal is finding the right criteria to retrieve one month ago from today or this month, in two digits. enter image description here Currently Month(now()) gives 10, but I hope to get 09, not 9.
I tried DateSerial, getDate(), pretty anything I could think of or online. But none of them worked. Any advice on this would be highly appreciated! Thank you!


Solution

  • You can use the following:

    Format(DateAdd("m", -1, Now()), "MM")
    

    The DateAdd part substracts the current date by one month, the Format part outputs the month in the MM format (with leading zero)