How do I add a calculated field that calculates a number of days?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paige Collins
    New Member
    • Apr 2012
    • 1

    How do I add a calculated field that calculates a number of days?

    I need to calculate a shipping efficency. I have two sets of data, OrderDate and ShipDate, I need to Figure out how long it took each order to ship. Essientially I need to minus the Ship date from the Order date in a new field, entitiled "DaysToShip ". I'm new to access, so thank you for the help!!

    P.s. If you need more information or I'm not being clear please let me know.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Are these two sets of data fields in a single table? The table name would help if so. I'm also assuming you want to create a query to show both the table fields and the calculated field [DaysToShip]. If so, your query would look something like :
    Code:
    SELECT [OrderDate]
         , [ShipDate]
         , DateDiff('d',[OrderDate],[ShipDate]) AS [DaysToShip]
    FROM   [YourTable]

    Comment

    • roshan ban
      New Member
      • Apr 2012
      • 21

      #3
      As you wand to minus the shipped date I think this code will help you
      Code:
      SELECT [OrderDate]
      , [ShipDate]
      , DateDiff('dd',[OrderDate],[ShipDate]-1) AS [DaysToShip]
      FROM [YourTable]
      In Access Query Desing View Try This code, It may work
      Code:
      select DateDiff(dd,OrderDate,ShippedDate)-1
      Last edited by NeoPa; Apr 29 '12, 10:29 AM. Reason: Merged posts and added [CODE] tags THAT ARE NOT OPTIONAL.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        @Roshan.
        As you have simply used my suggested code with a couple of minor changes let me just deal with the changes :
        1. You changed 'd' to 'dd'. This simply makes the call fail as 'dd' is not a valid parameter to DateDiff().
        2. You subtracted one from the calculation. This simply causes the calculation to give an incorrect result.

        In your second suggestion you took dd out of the quotes. This simply makes no sense and cannot possibly work (without a predefined object / field named dd which is not the case here).

        Comment

        • roshan ban
          New Member
          • Apr 2012
          • 21

          #5
          The sugestion work in case Of MySql Check the code.Thanks for comment
          Last edited by NeoPa; Apr 29 '12, 12:00 PM. Reason: Removed unnecessary quote.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            This is an Access question in an Access forum and it doesn't work in Access. I'm pretty sure nothing else is relevant.

            Comment

            Working...