Skip to content

DatePart


Gets an interval from a date

Syntax

` declare function DatePart ( byref interval as const string, byval date_serial as double, byval firstdayofweek as long = fbUseSystem, byval firstdayofyear as long = fbUseSystem ) as long

`

Usage

#include "vbcompat.bi"
result = DatePart( interval, date_serial, first_dayofWeek [, first_week_of_year ] )

Parameters

interval

string indicating which part of the date is required

date_serial

the date serial to decode

firstdayofweek

first day of the week

firstdayofyear

first day of the year

Return Value

Return an integer representing the interval in the Date Serial.

Description

interval string indicating which part of the date is required is specified as follows:

valueinterval
yyyyyears
qquarter(three months)
mmonths
wweekday
wwweek of the year
yday of the year
dday of the month
hhours
nminutes
sseconds

first_dayofweek Affects the output when 'w' interval is required.

valuefirst day of weekconstant
omittedsunday
0local settingsfbUseSystem
1sundayfbSunday
2mondayfbMonday
3tuesdayfbTuesday
4wednesdayfbWednesday
5thursdayfbThursday
6fridayfbFriday
7saturdayfbSaturday

first_weekofyear specifies which year (previous or next) that the week which spans the end of one year and the beginning of the next should included with. Affects the output when 'ww' interval is required.

valuefirst week of yearconstant
0local settingsfbUseSystem
1January 1's weekfbFirstJan1
2first weeks having 4 days in the yearfbFirstFourDays
3first full week of yearfbFirstFullWeek

The compiler will not recognize this function unless vbcompat.bi or datetime.bi is included.

Examples

start GeSHi

vb
#include "vbcompat.bi"

Dim d As Double

d = Now()

Print "Today is day " & DatePart( "y", d );
Print " in week " & DatePart( "ww", d );
Print " of the year " & DatePart( "yyyy", d )

end GeSHi

Differences from QB

  • Did not exist in QB. This function appeared in Visual Basic.

See also

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft