Results 1 to 3 of 3
  1. #1
    choe is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Posts
    1

    Need to calcuate fields between dates


    I have a database that I need to calculate a query that is based on 3 dates. For example...I have an admission date and a discharge date in my database. If there is no date in the discharge date then I need it to calculate the number of days between the admission date and "today's date." If there is a discharge date then I need to calculate the difference between admission date and discharge date. Basically i need a length of stay figure. I can figure the formula in excel but cannot get it to work in access. Here is my formula in excel =If(ISBLANK(DischargeDate),Sum(today()),sum(Discha rgeDate-AdmissionDate). Can someone help me?

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Need to use DateDiff() function.

    Try
    Code:
    DateDiff("d",[AdmissionDate],Nz([DischargeDate],Date()))
    Last edited by ssanfu; 08-10-2015 at 01:04 PM. Reason: PBKAC :( Pasted in the wrong function

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I would use a UNION query

    SELECT [admission date],[DISCHARGE date],DATEDIFF("D", [admission date],DATE()) AS DAYS WHERE [discharge date] IS NULL
    UNION
    SELECT [admission date],[DISCHARGE date],DATEDIFF("D", [admission date],[DISCHARGE date]) AS DAYS WHERE [discharge date] IS NOT NULL

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calcuate How many days remain in sharepoint
    By sdc1234 in forum SharePoint
    Replies: 2
    Last Post: 10-01-2014, 05:51 AM
  2. Same dates different fields compare
    By Ruegen in forum Programming
    Replies: 3
    Last Post: 11-18-2013, 10:57 PM
  3. Replies: 2
    Last Post: 11-04-2013, 10:55 AM
  4. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  5. Dates & Days Fields
    By djclntn in forum Database Design
    Replies: 5
    Last Post: 10-22-2011, 06:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums