DatePart

FreeBASIC

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
w weekday
ww week 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.

Example

#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 )


Differences from QB

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

See also