DatePart Function

DatePart แƒคแƒฃแƒœแƒฅแƒชแƒ˜แƒ แƒแƒ‘แƒ แƒฃแƒœแƒ”แƒ‘แƒก แƒ—แƒแƒ แƒ˜แƒฆแƒ˜แƒก แƒ™แƒแƒœแƒ™แƒ แƒ”แƒขแƒฃแƒš แƒœแƒแƒฌแƒ˜แƒšแƒก.

Syntax:


DatePart (interval As String, date As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Long

แƒ“แƒแƒ‘แƒ แƒฃแƒœแƒ”แƒ‘แƒฃแƒšแƒ˜ แƒ›แƒœแƒ˜แƒจแƒ•แƒœแƒ”แƒšแƒแƒ‘แƒ:

The extracted part for the given date.

Parameters:

interval - A string expression from the following table, specifying the date interval.

interval (string value)

แƒแƒฎแƒกแƒœแƒ

yyyy

Year

q

Quarter

m

Month

y

Day of year

w

Weekday

ww

Week of year

d

Day

h

Hour

n

Minute

s

Second


date - The date from which the result is calculated.

Date literals allow to specify unambiguous date variables that are independent from the current language. Literals are enclosed between hash signs #. Possible formats are:

firstdayofweek: An optional parameter that specifies the starting day of a week.

firstdayofweek value

แƒแƒฎแƒกแƒœแƒ

0

Use system default value

1

แƒ™แƒ•แƒ˜แƒ แƒ (แƒกแƒแƒฌแƒงแƒ˜แƒกแƒ˜)

2

แƒแƒ แƒจแƒแƒ‘แƒแƒ—แƒ˜

3

แƒกแƒแƒ›แƒจแƒแƒ‘แƒแƒ—แƒ˜

4

แƒแƒ—แƒฎแƒจแƒแƒ‘แƒแƒ—แƒ˜

5

แƒฎแƒฃแƒ—แƒจแƒแƒ‘แƒแƒ—แƒ˜

6

แƒžแƒแƒ แƒแƒกแƒ™แƒ”แƒ•แƒ˜

7

แƒจแƒแƒ‘แƒแƒ—แƒ˜


firstweekofyear: An optional parameter that specifies the starting week of a year.

firstweekofyear value

แƒแƒฎแƒกแƒœแƒ

0

Use system default value

1

แƒ™แƒ•แƒ˜แƒ แƒ 1 แƒแƒ แƒ˜แƒก แƒ™แƒ•แƒ˜แƒ แƒ แƒ˜แƒแƒœแƒ•แƒ แƒ˜แƒ—, แƒžแƒ˜แƒ แƒ•แƒ”แƒšแƒ˜ (แƒกแƒแƒฌแƒงแƒ˜แƒกแƒแƒ“)

2

แƒ™แƒ•แƒ˜แƒ แƒ 1 แƒแƒ แƒ˜แƒก แƒžแƒ˜แƒ แƒ•แƒ”แƒšแƒ˜ แƒ™แƒ•แƒ˜แƒ แƒ, แƒ แƒแƒ›แƒ”แƒšแƒ˜แƒช แƒจแƒ”แƒ˜แƒชแƒแƒ•แƒก แƒแƒ› แƒ™แƒ•แƒ˜แƒ แƒ˜แƒก แƒแƒ—แƒฎ แƒแƒœ แƒ›แƒ”แƒข แƒ“แƒฆแƒ”แƒก

3

แƒ™แƒ•แƒ˜แƒ แƒ 1 แƒแƒ แƒ˜แƒก แƒžแƒ˜แƒ แƒ•แƒ”แƒšแƒ˜ แƒ™แƒ•แƒ˜แƒ แƒ, แƒ แƒแƒ›แƒ”แƒšแƒ˜แƒช แƒจแƒ”แƒ˜แƒชแƒแƒ•แƒก แƒ›แƒฎแƒแƒšแƒแƒ“ แƒแƒฎแƒแƒšแƒ˜ แƒฌแƒ˜แƒšแƒ˜แƒก แƒ“แƒฆแƒ”แƒ”แƒ‘แƒก


Example:


Sub example_datepart
    MsgBox DatePart("ww", #01/02/2005#) ' displays 2 because weeks start on Sunday
    MsgBox DatePart("ww", #12/31/2005#) ' displays 53
    MsgBox DatePart(date:=#2005-12-30#, interval:="q") ' displays 4
End Sub

Please support us!