Custom Search
 


MS Access DatePart function



DatePart function can be used in both Access queries and VBA code. It evaluates a date/time value and returns a specific interval part (an integer or variant) of the date/time value.

Click the link below to see examples of how to use DatePart function:

Access quries example

DatePart function syntax:

There are three forms of DatePart function that can be used.

  1. DatePart (interval, date)
  2. DatePart (interval, date, firstdayofweek)
  3. DatePart (interval, date, firstdayofweek, firstweekofyear)

Function Parameters:

Parameter Required/Optional Description
interval Required Interval is the abbreviation for a specific part of a date/time value you want to retrieve. The interval can be Year, Quarter, Month, Day of year, Day, Weekday, Week, Hour, Minute, Second.

The interval parameter settings:

Setting Description
yyyy Year (four-digit number)
q Quarter of year
m Month
y Day of year
d Day of month
w Weekday
ww Week of year
h Hour
n Minute
s Second
date Required This is the date/time value that is to be evaluated.

The date/time value can be a field name with a Date/Time data type, a variable of date data type in VBA, or a date literal.

A variable is an unknown value at design time but will be dynamically assigned a specific value at program run-tim.

Date literal is a known value of any sequence of characters with a valid format that is surrounded by number signs (#) such as such as #7-Nov-93#. Valid formats include the date format specified by the date locale settings (in Control Panel's Regional Options) for your code or the universal date format.

For example, #12/31/92# is the date literal that represents December 31, 1992, where English-U.S. is the locale setting for your application. Use date literals to maximize portability across national languages.

firstdayofweek Optional A constant that specifies the first day of the week. Because this parameter is optional, you don't have to specify it in the function. If not specified, Sunday is assumed to be the first day of the week.

The firstdayofweek argument affects DatePart calculations that return Weekday part of the date value evaluated. The corresponding interval symbol for Weekday is "w" (without quotes).

The firstdayofweek argument has these settings. Note: Constants listed here can be used in VBA code to replace the actual values.

Constant Value Description
vbUseSystem 0 Use the NLS API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
firstweekofyear Optional A constant that specifies the first week of the year. Because this parameter is optional, you don't have to specify it in the function. If not specified, the first week is assumed to be the week in which January 1 occurs.

The firstweekofyear argument affects DatePart calculations that return Week part of the date value evaluated. The corresponding interval symbol for Week is "ww" (without quotes).

The firstweekofyear argument has these settings. Note: Constants listed here can be used in VBA code to replace the actual values.

Constant Value Description
vbUseSystem 0 Use the NLS API setting.
vbFirstJan1 1 Start with week in which January 1 occurs (default).
vbFirstFourDays 2 Start with the first week that has at least four days in the new year.
vbFirstFullWeek 3 Start with first full week of the year.



Copyright© GeeksEngine.com



Other Recent Articles from the MS Access category:

1.Examples of MS Access DateDiff function used in query and VBA code
2.MS Access DateDiff function
3.How to find out your computer name and username by VBA
4.Examples of MS Access DatePart function
5.Examples of MS Access DateAdd function
6.MS Access DateAdd function
7.IIF function basics - the CASE statement of MS Access
8.MS Access Date Expression
9.Solved: MS Access error "The text is too long to be edited"
10.Create MS Access Combo Box essential properties by VBA code
11.Create MS Access Combo Box essential properties manually
12.How to do text search in MS Access programmatically
13.Solved - the size of the Access query result is larger than the maximum size of a database (2 GB)
14.How to easily get a list of field names in MS Access
15.How to count distinct records in MS Access
16.How to do transaction based processing in MS Access
17.How to open a document (local/network file or web page) from MS Access
18.How to use ADOX to create unique composite index - the VBA approach
19.How to do cross-table update queries in MS Access - the right way
20.Three efficient ways to get the number of records by using VBA
21.How to create a composite unique index (not as a primary key) in MS Access
22.Use VBA to get the correct number of records in a Recordset object
23.Disable Access Prompt when a record is changed, table deleted, or action queries run
24.How to hide and unhide a MS Access object
25.How to return multiple values from a VBA function (Part 3)
26.How to return multiple values from a VBA function (Part 2)
27.How to return multiple values from a VBA function (Part 1)
28.Three ways to programmatically duplicate a table in MS Access by VBA
29.Create a DLL by CSharp or VB.Net for VBA
30.How to correctly reference and call a DLL
31.How to register a C# or VB.Net DLL
32.Email address validation by Regular Expressions using VBA
33.Fix MS Access error: Query must have at least one destination field
34.How to unselect radio buttons in MS Access after it has been selected
35.How to Change Query Timeout Value for MS Access SQL Queries
36.What is Northwind Traders database

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