The BirtDateTime class provides functions to determine the amount of time between two dates or times, to add or subtract time spans, and to get parts of a date. Since date spans are just numbers, the application can use normal math on them: multiplication, division, addition, subtraction, and so on. This class is static. The application cannot create instances of the class.

This function returns a new date that results from adding a given number of days to a date. The number of days to add can be negative. In this case, the result is as if that number is subtracted from the date.

Syntax

Parameters

date

A date object that represents the start date.

n

The number of days to add to the date.

Returns

A date that results from adding the specified number of days to the start date.

Examples

The following example adds days to a specific date:

The following example adds 15 days to each date value in the InvoiceDate field:

This function returns a new date that results from adding a given number of hours to a date. The number of hours to add can be negative. In this case, the result is as if that number is subtracted from the date.

Syntax

Parameters

date

A date object that represents the start date. If a start date does not have a time value, the function assumes the time is midnight (00:00:00).

n

The number of hours to add to the date.

Returns

A date that results from adding the specified number of hours to the start date.

Examples

The following example adds hours to a specific date and time:

The following example adds 36 hours to each date value in the StartTime field:

This function returns a new date that results from adding a given number of minutes to a date. The number of minutes to add can be negative. In this case, the result is as if that number is subtracted from the date.

Syntax

Parameters

date

A date object that represents the start date. If a start date does not have a time value, the function assumes the time is midnight (00:00:00).

n

The number of minutes to add to the date.

Returns

A date that results from adding the specified number of minutes to the start date.

Examples

The following example adds minutes to a specific date and time:

The following example adds 15 minutes to each date value in the StartTime field:

This function returns a new date that results from adding a given number of months to a date. The number of months to add can be negative. In this case, the result is as if that number is subtracted from the date.

This function always returns a valid date. If necessary, the day part of the resulting date is adjusted downward to the last day of the resulting month in the resulting year. For example, if you add 1 month to Jan 31, 2008, addMonth( ) returns Feb 29, 2008 (2008 is a leap year), not Feb 31, 2008.

Syntax

Parameters

date

A date object that represents the start date.

n

The number of months to add to the date.

Returns

A date that results from adding the specified number of months to the start date.

Examples

The following example adds months to a specific date:

The following example adds 10 months to each date value in the InvoiceDate field:

This function returns a new date that results from adding a given number of quarters to a date. A quarter is equal to three months. For example, if you add 2 quarters to Sep 10, 2008, the function returns Mar 10, 2008. The number of quarters to add can be negative. In this case, the result is as if that number is subtracted from the date.

Syntax

Parameters

date

A date object that represents the start date.

n

The number of quarters to add to the date.

Returns

A date that results from adding the specified number of quarters to the start date.

Examples

The following example adds quarters to a specific date:

var startDate = "2008-12-15";

The following example adds 2 quarters to each date value in the ForecastClosing field:

This function returns a new date that results from adding a given number of seconds to a date. The number of seconds to add can be negative. In this case, the result is as if that number is subtracted from the date.

Syntax

Parameters

date

A date object that represents the start date. If a start date does not have a time value, the function assumes the time is midnight (00:00:00).

n

The number of seconds to add to the date.

Returns

A date that results from adding the specified number of seconds to the start date.

Examples

The following example adds seconds to a specific date and time:

var startDate = "2008-12-31 10:30:00";

The following example adds 6000 seconds to each date value in the StartTime field:

This function returns a new date that results from adding a given number of weeks to a date. The number of weeks to add can be negative. In this case, the result is as if that number is subtracted from the date.

Syntax

Parameters

date

A date object that represents the start date.

n

The number of weeks to add to the date.

Returns

A date that results from adding the specified number of weeks to the start date.

Examples

The following example adds weeks to a specific date:

The following example adds 2 weeks to each date value in the InvoiceDate field:

This function returns a new date that results from adding a given number of years to a date. The number of years to add can be negative. In this case, the result is as if that number is subtracted from the date.

Syntax

Parameters

date

A date object that represents the start date.

n

The number of years to add to the date.

Returns

A date that results from adding the specified number of years to the start date.

Examples

The following example adds years to a specific date:

The following example adds 5 years to each date value in the HireDate field:

This function returns a number from 1 to 31 that represents the day of the month for a given date. For example, if the date is 2009-01-19, the function returns 19.

Syntax

Parameter

date

A date object from which to get the day.

Returns

A number that represents the day of the month for a given date.

Examples

The following example returns the day of the month for each value in the ShipDate field:

The following example returns the day of the month for the current date:

This function returns the number of days between two dates. A day is calculated by subtracting the day value of the first date from the day value of the second date. For example, if the first date is 2008-12-30 23:59:59 and the second date is 2008-12-31 00:00:00, the function returns 1 day, even though only one second separates the two dates.

Syntax

Parameters

date1

A date object that represents the start of the time span.

date2

A date object that represents the end of the time span.

Returns

The number of days between two dates.

Examples

The following example returns the number of days between specific dates:

The following example returns the number of days from the current date to the end of 2009:

The following example returns the number of days between values in the InvoiceDate and PaymentDate fields:

This function returns the number of hours between two dates. An hour is calculated by subtracting the hour value of the first date from the hour value of the second date. For example, if the first date is 2009-01-31 1:30:00 and the second date is 2009-01-31 2:00:00, the function returns 1 hour, even though only 30 minutes separates the two dates. If a date does not have a time value, the function assumes the time is midnight (00:00:00).

Syntax

Parameters

date1

A date object that represents the start of the time span.

date2

A date object that represents the end of the time span.

Returns

The number of hours between two dates.

Examples

The following example returns the number of hours between specific dates:

The following example returns the number of hours from the current date and time to the end of 2009:

The following example returns the number of hours between values in the StartTime and FinishTime fields:

This function returns the number of minutes between two dates. A minute is calculated by subtracting the minute value of the first date from the minute value of the second date. For example, if the first date is 2009-01-31 1:30:59 and the second date is 2009-01-31 1:31:00, the function returns 1 minute, even though only one second separates the two dates. If a date does not have a time value, the function assumes the time is midnight (00:00:00).

Syntax

Parameters

date1

A date object that represents the start of the time span.

date2

A date object that represents the end of the time span.

Returns

The number of minutes between two dates.

Examples

The following example returns the number of minutes between specific dates:

The following example returns the number of minutes from the current date and time to the beginning of 2010:

The following example returns the number of minutes between values in the StartTime and FinishTime fields:

This function returns the number of months between two dates. A month is calculated by subtracting the month value of the first date from the month value of the second date. For example, if the first date is 2009-01-31 and the second date is 2009-02-01, the function returns 1 month, even though only one day separates the two dates.

Syntax

Parameters

date1

A date object that represents the start of the time span.

date2

A date object that represents the end of the time span.

Returns

The number of months between two dates.

Examples

The following example returns the number of months between specific dates:

The following example returns the number of months from the current date to the beginning of 2010:

The following example returns the number of months between values in the ProjectStart and ProjectComplete fields:

This function returns the number of quarters between two dates. A quarter is calculated by subtracting the month value of the first date from the month value of the second date. A difference of 3 months is equal to 1 quarter. For example, if the first date is 2009-01-31 and the second date is 2009-07-01, the function returns 2. If the first date is 2009-01-01 and the second date is 2009-09-30, the function also returns 2.

Syntax

Parameters

date1

A date object that represents the start of the time span.

date2

A date object that represents the end of the time span.

Returns

The number of quarters between two dates.

Examples

The following example returns the number of quarters between specific dates:

The following example returns the number of quarters from the current date to the beginning of 2010:

The following example returns the number of quarters between values in the ProjectStart and ProjectComplete fields:

This function returns the number of seconds between two dates. If a date does not have a time value, the function assumes the time is midnight (00:00:00).

Syntax

Parameters

date1

A date object that represents the start of the time span.

date2

A date object that represents the end of the time span.

Returns

The number of seconds between two dates.

Examples

The following example returns the number of seconds between specific dates:

The following example returns the number of seconds from the current date and time to the beginning of 2010:

The following example returns the number of seconds between values in the StartTime and FinishTime fields:

This function returns the number of weeks between two dates. A month is calculated by subtracting the week number of the first date from the week number of the second date. For example, if the first date is 2009-01-02 (week 1 of the year) and the second date is 2009-01-05 (week 2 of the year), the function returns 1 week, even though only three days separates the two dates.

Syntax

Parameters

date1

A date object that represents the start of the time span.

date2

A date object that represents the end of the time span.

Returns

The number of weeks between two dates.

Examples

The following example returns the number of weeks between specific dates:

The following example returns the number of weeks from the current date to the beginning of 2010:

The following example returns the number of weeks between values in the ProjectStart and ProjectComplete fields:

This function returns the number of years between two dates. A year is calculated by subtracting the year value of the first date from the year value of the second date. For example, if the first date is 2009-01-01 and the second date is 2009-12-31, the function returns 0. If the first date is 2008-11-15 and the second date is 2009-01-15, the function returns 1.

Syntax

Parameters

date1

A date object that represents the start of the time span.

date2

A date object that represents the end of the time span.

Returns

The number of years between two dates.

Examples

The following example returns the number of years between specific dates:

The following example returns the number of years between each value in the HireDate field and the current date:

This function returns the month for a given date. Depending on the option you specify, the function returns the month as a number, the full month name, or the abbreviated month name. The month name is locale-specific.

Syntax

Parameters

date

A date object from which to get the month.

option

Optional. A number that represents the month format to return. Use one of the following values:

If you omit this argument, the function returns the month as a number.

Returns

The month for a given date.

Examples

The following example shows the month values returned for a specific date:

The following example returns the month for the current date:

This function returns the current date and time, for example, Feb 2, 2009 2:05 PM.

Syntax

Returns

The current date and time.

Example

The following example returns the number of hours from the current date and time to Christmas:

This function returns a number from 1 to 4 that represents the quarter in which a given date falls. The first quarter begins on January 1.

Syntax

Parameter

date

A date object from which to get the quarter number.

Returns

The quarter number for a given date.

Examples

The following example shows the quarter numbers returned for specific dates:

The following example returns the quarter number for each value in the CloseDate field:

The following example returns the quarter number for the current date:

This function returns the current date
that includes a time value of midnight, for example, Feb 2, 2009 12:00 AM.

Syntax

Returns

The current date with a time value of midnight.

Examples

The following example returns the number of days from the current date to Christmas:

The following example calculates the number of years from each value in the HireDate data field to the current date.

This function returns a number from 1 to 52 that represents the week number for a given date.

Syntax

Parameter

date

A date object from which to get the week number.

Returns

The week number for a given date.

Examples

The following example shows the week numbers returned for specific dates:

The following example returns the week number for each value in the CloseDate field:

The following example returns the week number for the current date:

This function returns the day of the week for a given date. Depending on the option you specify, the function returns the day of the week as a number, the full weekday name, or the abbreviated weekday name. The weekday name is locale-specific.

Syntax

Parameters

date

A date object from which to get the day of the week.

option

Optional. A number that represents the format to return. Use one of the following values:

If you omit this argument, the function assumes option 1.

Returns

The day of the week for a given date.

Examples

The following example shows the week day values returned for a specific date:

The following example returns the day of the week for the current date:

This function returns the four-digit year value for a given date. For example, if the date is 2009-01-19, the function returns 2009.

Syntax

Parameter

date

A date object from which to get the year.

Returns

The four-digit year value for a given date.

Examples

The following example returns the year for each value in the HireDate field:

The following example returns the year for the current date: