Description:-

This is used to get a specific part from a datetime object.

datePart( datepart_argument, datetime_object );

This function returns a part of a date, as an integer value.

Member Function Syntax:-

datetime_object.datePart( datepart_argument );

Attributes:-

datepart:- This is a required argument and it is a string field, the accepted values are in the below list.

datepart_valuedescription
yyyyIt will return the year.
qIt will return the quarter of the year.
mIt will return the month.
yIt will return the day number of the year.
dIt will return the day number of the month.
wIt will return the weekday number of 7 weekdays.
wwIt will return the week of the year.
hIt will return the hour.
nIt will return the minute.
sIt will return the second.
lIt will return the millisecond.

date:- This is a required argument, A date/time object in the range 100 AD – 9999 AD.

Example:-

var dateObject = "2025-11-21 04:35:45";
writeoutput( "The date is: #dateObject#.<br>" );
writeoutput( "The year: #datePart( "yyyy", dateObject )#.<br>" );
writeoutput( "The quarter: #datePart( "q", dateObject )#.<br>" );
writeoutput( "The month: #datePart( "m", dateObject )#.<br>" );
writeoutput( "The day of the year: #datePart( "y", dateObject )#.<br>" );
writeoutput( "The day of the month: #datePart( "d", dateObject )#.<br>" );
writeoutput( "The weekday of 7 weekdays: #datePart( "w", dateObject )#.<br>" );
writeoutput( "The week of the year: #datePart( "ww", dateObject )#.<br>" );
writeoutput( "The hour: #datePart( "h", dateObject )#.<br>" );
writeoutput( "The minute: #datePart( "n", dateObject )#.<br>" );
writeoutput( "The second: #datePart( "s", dateObject )#.<br>" );
writeoutput( "The millisecond: #datePart( "l", dateObject )#." );

Result:-

The date is: 2025-11-21 04:35:45.
The year: 2025.
The quarter: 4.
The month: 11.
The day of the year: 325.
The day of the month: 21.
The weekday of 7 weekdays: 6.
The week of the year: 47.
The hour: 4.
The minute: 35.
The second: 45.
The millisecond: 0.