Building a Date Expression

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

Guest

Hi- I'm building a database that will include a report by month, quarter and year on how much we spent renting specialty beds. I need to figure out how to build an expression that will tell me how many days in a given month the bed was in use. I can get the total number of days on the bed with this:

=IIf(IsNull([Date Off]),Date()-[Date On],[Date Off]-[Date On])

But I cannot figure out how to just capture a month's days. Somehow, I think I need to point to the last day of the month and subtract back to the date on or first day of the month (whichever applies), but how? I thought for a little while DateDiff might work but how?

Thanks in advance!
 
Hi,

Here's how you can get the End Of the Month:

=DateSerial(Year([DateOn]),Month([DateOn]),1)-1

From there I guess you can calculate the number of days between the End Of
the Month and [DateOn]


I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support
(e-mail address removed)
"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03-026.asp> and/or
to visit Windows Update at <http://windowsupdate.microsoft.com/> to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."

This posting is provided "AS IS" with no warranties, and confers no rights



--------------------
| Thread-Topic: Building a Date Expression
| thread-index: AcRTy4H0oa22sEiuRGKtqEvZA1J3vw==
| X-WBNR-Posting-Host: 65.115.175.40
| From: "=?Utf-8?B?TG9sYQ==?=" <[email protected]>
| Subject: Building a Date Expression
| Date: Wed, 16 Jun 2004 10:58:19 -0700
| Lines: 7
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.access.queries
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 127.0.0.1
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA
03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.access.queries:204113
| X-Tomcat-NG: microsoft.public.access.queries
|
| Hi- I'm building a database that will include a report by month, quarter
and year on how much we spent renting specialty beds. I need to figure out
how to build an expression that will tell me how many days in a given month
the bed was in use. I can get the total number of days on the bed with
this:
|
| =IIf(IsNull([Date Off]),Date()-[Date On],[Date Off]-[Date On])
|
| But I cannot figure out how to just capture a month's days. Somehow, I
think I need to point to the last day of the month and subtract back to the
date on or first day of the month (whichever applies), but how? I thought
for a little while DateDiff might work but how?
|
| Thanks in advance!
|
 
Slight error in that. Assuming you want the last day in whatever month
DateOn contains, you need

=DateSerial(Year([DateOn]),Month([DateOn]) + 1,1)-1

or

=DateSerial(Year([DateOn]),Month([DateOn]) + 1, 0)

The formula given will give you the last day of the previous month.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Eric Butts said:
Hi,

Here's how you can get the End Of the Month:

=DateSerial(Year([DateOn]),Month([DateOn]),1)-1

From there I guess you can calculate the number of days between the End Of
the Month and [DateOn]


I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support
(e-mail address removed)
"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03-026.asp> and/or
to visit Windows Update at <http://windowsupdate.microsoft.com/> to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."

This posting is provided "AS IS" with no warranties, and confers no rights



--------------------
| Thread-Topic: Building a Date Expression
| thread-index: AcRTy4H0oa22sEiuRGKtqEvZA1J3vw==
| X-WBNR-Posting-Host: 65.115.175.40
| From: "=?Utf-8?B?TG9sYQ==?=" <[email protected]>
| Subject: Building a Date Expression
| Date: Wed, 16 Jun 2004 10:58:19 -0700
| Lines: 7
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.access.queries
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 127.0.0.1
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA
03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.access.queries:204113
| X-Tomcat-NG: microsoft.public.access.queries
|
| Hi- I'm building a database that will include a report by month, quarter
and year on how much we spent renting specialty beds. I need to figure out
how to build an expression that will tell me how many days in a given month
the bed was in use. I can get the total number of days on the bed with
this:
|
| =IIf(IsNull([Date Off]),Date()-[Date On],[Date Off]-[Date On])
|
| But I cannot figure out how to just capture a month's days. Somehow, I
think I need to point to the last day of the month and subtract back to the
date on or first day of the month (whichever applies), but how? I thought
for a little while DateDiff might work but how?
|
| Thanks in advance!
|
 
I would probably do this with a function. You need to know 4 things - the
dateOn, DateOff, StartOfPeriod, and End of Period. And then you need to
calculate which dates to use.

I THINK that the following UNTESTED statement MIGHT work for you.

DateDiff("d", IIF(DateON>StartOfPeriod,DateON,StartOfPeriod), IIF(DateOff is
Null Or DateOff>EndOfPeriod,EndOfPeriod,DateOff))
 
Back
Top