QUERY Help: Time Differences for 2 fields on same table?

floridaboy2004

New Member
Joined
Nov 17, 2004
Messages
44
Hello all,

I have a table named 'CUSTOMERS.' This table has, among others, 2 fields called 'purchase time' and 'initial entry time.'

I want to evaluate the shopping pace of my customers and I want to select out ONLY those customers that made a 'purchase (time)' within 2 hours or less of their 'initial entry time' in my store.

FYI, the 'purchase time' and the 'initial entry time' are in Short Time (03:45) format (with no A.M. or P.M. designation, etc.).

Is there a way to specify for this during the creation of a query?

Any help/suggestions for formulas would be most helpful.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I think you need to make an expression in the query using the DateDiff function.

eg

ElapsedHours:DateDiff("h", InitialEntryTime, PurchaseTime)

or

ElapsedMins:DateDiff("n", InitialEntryTime, PurchaseTime)

You could then apply appropriate criteria against the expression.
 
Upvote 0
Hello Norie,

I tried doing what you suggested and using '<2' (for 2 hours or less) as my criteria but it is giving me values such as '-3064425' when I use 2 times such as '21:29' and '22:15.'

How should I write my criteria to give me ALL values where the purchase time is less than 2 hours of the initial entry time?

Thanks for your patience and generosity! :)
 
Upvote 0
Hi,

the following should work

for time-diff in minutes:
Datediff("n","21:29","22:30")

for time-diff in seconds:
Datediff("s","21:29","22:30")


For example, a query could look like this:

SELECT * FROM [TABLE_NAME]
WHERE datediff("n",enter,purchase)<=120

Don't compare the times in hours, because the Differenz between 19:15 and 21:00 will be 2 hours for access ...

hope this help you
 
Upvote 0

Forum statistics

Threads
1,221,832
Messages
6,162,254
Members
451,757
Latest member
iours

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top