|
Custom Search
| |
|
Examples of MS Access DateDiff function used in query and VBA code
The date format in the examples below is determined by the Short date format that was set in in Control Panel's Regional Options. For detailed description of DateDiff function, refer to this page. Example queries below can be pasted to MS Access' query design and run as is. Please note: The firstdayofweek argument takes default value Sunday and firstweekofyear takes the week in which the first of January occurs.
More examples: DateDiff function can be used in SQL queries WHERE, GROUP BY, HAVING, SORT BY... 1. Get the average days that orders were fullfilled based on the number of days between order date and shipment date. The result is 8.49 days where ROUND function is used to round the value to 2 decimal points. select ROUND(AVG(DateDiff("d",OrderDate, ShippedDate)),2) as Average_Delivery_Days from Orders 2. VBA code example
Private Sub Command0_Click() Dim dteTimeStart As Date Dim dteTimeEnd As Date dteTimeStart = Now() '' Add 5 hours to the start time dteTimeEnd = DateAdd("h", 5, dteTimeStart) '' Calculate the number of minutes between start and end time MsgBox "Number of minutes is: " & DateDiff("n", dteTimeStart, dteTimeEnd) End Sub
Happy Coding! |
Copyright © 2024 GeeksEngine.com. All Rights Reserved. This website is hosted by HostGator. No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it. |
Home | Feedback | Terms of Use | Privacy Policy |