Solved

How do I select last date of previous month?

Posted on 2014-07-31
7
327 Views
Last Modified: 2014-08-01
How do I alter the below to select last day of previous month rather than current date?

0-365: Sum(((IIf([ORDER_DATE]>=Date()-365,[AMOUNT_BILLED],0))))
0
Comment
Question by:garyrobbins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 75
ID: 40232823
The last day of the previous month:
DateSerial(Year(Date()), Month(Date()),0)

mx
0
 
LVL 75
ID: 40232828
And this should come in handy:

Functions for calculating and for displaying Date/Time values in Access:

http://support.microsoft.com/kb/210604

mx
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 40232834
First day of current month can be found with DateSerial(Year(Date()), Month(Date()), 1)

Last day of previous month is DATEAD that -1

Kelvin
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 195 total points
ID: 40232867
So I guess:

0-365: Sum(((IIf([ORDER_DATE]>= DateSerial(Year(Date()), Month(Date()),0) ,[AMOUNT_BILLED],0))))
0
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 195 total points
ID: 40233083
Previous comments look fine.
Just to clarify the concept and avoid remebering functions.

Required date: DateSerial (year, month, day)

In general,
1.  if day is set to 0 then it borrows 1 month. The month value is reduced by 1. The days added are those corresponding to the number of days in new month. If the month value becomes 0 then it is treated as in in next step.
2. If month is 0, then a year (12 months) is add to month value. The year value is reduced by 1.
Examples: Remember, calculating age
   DateSerial(2014,1,0)     ===>   2013, 12, 31
                                           0 days + 31 because the month will be 12, month 0  borrows 12 month from year part.
                                           0+12 months borrowing 1 year, the year becomes 2013
   DateSerial(2014,0,0)     ===>   2013, 11, 30

Now this should be obvious:
   DateSerial (currentYear, CurrentMonth, 0) ===> last of previous month - If currentMonth is 11 then result is last month of 10.
  DateSerial (currentYear, CurrentMonth, 1) ===> first of current month unless currentMonth =0, where it will be 1irst of December of last previous year.
0
 

Author Closing Comment

by:garyrobbins
ID: 40234098
Thank you both, first for putting in the thread like that, Joe and the explanation HNASR.  Working Great.
0
 
LVL 30

Expert Comment

by:hnasr
ID: 40234527
Welcome!
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question