DatePart: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
DatePart(''interval'', ''date''[, ''firstdayofweek''[, ''firstweekofyear'']]) | |||
== Description == | |||
DatePart returns a number specifying a part of the given date. The required parameter, ''interval'', determines the part of date which is measured and returned. The optional parameter ''firstdayofweek'' is Sunday, if not specified The optional ''firstweekofyear'' is the week containing January 1, if not specified. | |||
== Example == | |||
<pre> | <pre> | ||
REM | REM DatePart Example | ||
' | 'DatePart returns a numberfrompartofadate | ||
DIM QuarterPart, MonthPart, DayPart | DIM QuarterPart, MonthPart, DayPart | ||
QuarterPart = | QuarterPart = DatePart("q", NOW) | ||
MonthPart = | MonthPart = DatePart("m", NOW) | ||
DayPart = | DayPart = DatePart("d", NOW) | ||
PRINT "Today is day " & DayPart | PRINT "Today is day " & DayPart | ||
PRINT "of month " & MonthPart | PRINT "of month " & MonthPart | ||
Line 19: | Line 19: | ||
</pre> | </pre> | ||
== Output == | |||
<pre> | <pre> | ||
Line 28: | Line 28: | ||
</pre> | </pre> | ||
== Related Items == | |||
[[dateadd|DATEADD]], [[datediff|DATEDIFF]] | [[dateadd|DATEADD]], [[datediff|DATEDIFF]] | ||
[[Category:Language Reference]] |
Revision as of 20:43, 8 August 2012
DatePart(interval, date[, firstdayofweek[, firstweekofyear]])
Description
DatePart returns a number specifying a part of the given date. The required parameter, interval, determines the part of date which is measured and returned. The optional parameter firstdayofweek is Sunday, if not specified The optional firstweekofyear is the week containing January 1, if not specified.
Example
REM DatePart Example 'DatePart returns a numberfrompartofadate DIM QuarterPart, MonthPart, DayPart QuarterPart = DatePart("q", NOW) MonthPart = DatePart("m", NOW) DayPart = DatePart("d", NOW) PRINT "Today is day " & DayPart PRINT "of month " & MonthPart PRINT "in quarter " & QuarterPart
Output
Today is day 18 of month 8 in quarter 3 (''sample output from August 18, 1998'')