DatePart

Extracts a part from a datetime value as a numeric.

Method Signature

DatePart(datepart=[string], date=[any], timezone=[string])

Arguments

Argument
Type
Required
Description
Default

datepart

string

true

The part of the date to extract.

date

any

true

The date to extract the part from.

timezone

string

false

An optional, explicit timezone to apply to the date.

Examples

All dateparts

This example shows information available from datePart

<bx:set todayDate = now() >
<h3>datePart Example</h3>
<p>Today's date is <bx:output>#todayDate#</bx:output>.
<p>Using datePart, we extract an integer representing the dateparts from that value <bx:output>
<ul>
<li>year: #datePart( "yyyy", todayDate )#</li>
<li>quarter: #datePart( "q", todayDate )#</li>
<li>month: #datePart( "m", todayDate )#</li>
<li>day of year: #datePart( "y", todayDate )#</li>
<li>day: #datePart( "d", todayDate )#</li>
<li>weekday: #datePart( "w", todayDate )#</li>
<li>week: #datePart( "ww", todayDate )#</li>
<li>hour: #datePart( "h", todayDate )#</li>
<li>minute: #datePart( "n", todayDate )#</li>
<li>second: #datePart( "s", todayDate )#</li>
</ul>
</bx:output>

Additional Examples

Last updated

Was this helpful?