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.
BirtDateTime.addDay
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
Date BirtDateTime.addDay( Date date, Number n )
Parameters
date
Date object. A date object that represents the start date.
n
Number object. The number of days to add to the date. Decimals are treated as integers, rounded down to the nearest integer.
Returns
Date object. 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:
BirtDateTime.addDay( row["InvoiceDate"], 15 )
BirtDateTime.addHour
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
Date BirtDateTime.addHour( Date date, Number n )
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
Number object. The number of hours to add to the date.
Returns
Date object. 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:
endDate = BirtDateTime.addHour( startDate, -8 ); // returns Dec 31, 2008 7:00 AM
The following example adds 36 hours to each date value in the StartTime field:
BirtDateTime.addHour( row["StartTime"], 36 )
BirtDateTime.addMinute
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
Date BirtDateTime.addMinute( Date date, Number n )
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
Number object. The number of minutes to add to the date.
Returns
Date object. 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:
BirtDateTime.addMinute( row["StartTime"], 15 )
BirtDateTime.addMonth
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
Date BirtDateTime.addMonth( Date date, Number n )
Parameters
date
Date object. A date object that represents the start date.
n
Number object. The number of months to add to the date. Decimals are treated as integers, rounded down.
Returns
Date object. 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:
BirtDateTime.addMonth( row["InvoiceDate"], 10 )
BirtDateTime.addQuarter
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, 2009. 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
Date BirtDateTime.addQuarter( Date date, Number n )
Parameters
date
A date object that represents the start date.
n
Number object. The number of quarters to add to the date.
Returns
Date object. 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";
var endDate;
endDate = BirtDateTime.addQuarter( startDate, 1 ); //returns Mar 15, 2009
endDate = BirtDateTime.addQuarter( startDate, -2 ); //returns Jun 15, 2008
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
Date BirtDateTime.addSecond( Date date, Number n )
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
Number object. The number of seconds to add to the date.
Returns
Date object. The result from adding the specified number of seconds to the start date.
Examples
The following example adds seconds to a specific date and time:
The following example adds 6000 seconds to each date value in the StartTime field:
BirtDateTime.addSecond( row["StartTime"], 6000 )
BirtDateTime.addWeek
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
Date BirtDateTime.addWeek( Date date, Number n )
Parameters
date
A date object that represents the start date.
n
Number Object. The number of weeks to add to the date.
Returns
Date object. 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:
BirtDateTime.addWeek( row["InvoiceDate"], 2 )
BirtDateTime.addYear
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
Date BirtDateTime.addYear( Date date, Number n )
Parameters
date
A date object that represents the start date.
n
Number object.The number of years to add to the date. Decimals are treated as integers, rounded down.
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:
BirtDateTime.addYear( row["HireDate"], 5 )
BirtDateTime.day
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
integer BirtDateTime.day( Date date )
Parameter
date
Date object. A date object from which to get the day.
Returns
An integer 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:
BirtDateTime.day( row["ShipDate"] )
The following example returns the day of the month for the current date:
BirtDateTime.day( (BirtDateTime.today())
BirtDateTime.diffDay
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
integer BirtDateTime.diffDay( Date date1, Date date2 )
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
Integer. The number of days between two dates.
Examples
The following example returns the number of days between specific dates:
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
integer BirtDateTime.diffHour( Date date1, Date date2 )
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
Integer. The number of hours between two dates.
Examples
The following example returns the number of hours between specific dates:
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
integer BirtDateTime.diffMinute( Date date1, Date date2 )
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
Integer. The number of minutes between two dates.
Examples
The following example returns the number of minutes between specific dates:
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
integer BirtDateTime.diffMonth( Date date1, Date date2 )
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
Integer. The number of months between two dates.
Examples
The following example returns the number of months between specific dates:
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
integer BirtDateTime.diffQuarter( Date date1, Date date2 )
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
Integer. The number of quarters between two dates.
Examples
The following example returns the number of quarters between specific dates:
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
integer BirtDateTime.diffSecond( date1, date2 )
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
Integer. The number of seconds between two dates.
Examples
The following example returns the number of seconds between specific dates:
This function returns the number of weeks between two dates. A week 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 one week, even though only three days separates the two dates.
Syntax
integer BirtDateTime.diffWeek( Date date1, Date date2 )
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
Integer. The number of weeks between two dates.
Examples
The following example returns the number of weeks between specific dates:
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
integer BirtDateTime.diffYear( Date date1, Date date2 )
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
Integer. The number of years between two dates.
Examples
The following example returns the number of years between specific dates:
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
integer BirtDateTime.diffYear( Date date1, Date date2 )
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
Integer. The number of years between two dates.
Examples
The following example returns the number of years between specific dates:
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
string BirtDateTime.month( Date date, integer option )
Parameters
date
A date object from which to get the month.
option
Integer. Optional. A number that represents the month format to return. Use one of the following values:
1 to get the month as a number from 1 to 12
2 to get the full month name, for example, January
3 to get the abbreviated month name, for example, Jan
If you omit this argument, the function returns the month as a number.
Returns
String. The month for a given date.
Examples
The following example shows the month values returned for a specific date:
BirtDateTime.month( "2009-02-15" ) // returns 2
BirtDateTime.month( "2009-02-15", 2 ) // returns February
BirtDateTime.month( "2009-02-15", 3) // returns Feb
The following example returns the month for the current date:
BirtDateTime.month( (BirtDateTime.today() )
BirtDateTime.now
This function returns the current date and time, for example, Feb 2, 2009 2:05 PM.
Syntax
Date BirtDateTime.now( )
Returns
Date object. 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 52 that represents the week number for a given date.
Syntax
integer BirtDateTime.week( date )
Parameter
date
A date object from which to get the week number.
Returns
Integer. The week number for a given date.
Examples
The following example shows the week numbers returned for specific dates:
BirtDateTime.week( "2009-02-15" ) // returns 8
BirtDateTime.week( "2009-10-12" ) // returns 42
The following example returns the week number for each value in the CloseDate field:
BirtDateTime.week( row["CloseDate"] )
The following example returns the week number for the current date:
BirtDateTime.week( (BirtDateTime.today() )
BirtDateTime.weekDay
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
string BirtDateTime.weekDay( Date date, integer option )
Parameters
date
A date object from which to get the day of the week.
option
Integer. Optional. A number that represents the format to return. Use one of the following values:
1 to get the day as a number from 1 (Sunday) to 7 (Saturday)
2 to get the day as a number from 1 (Monday) to 7 (Sunday)
3 to get the day as a number from 0 (Monday) to 6 (Sunday)
4 to get the full weekday name, for example, Wednesday
5 to get the abbreviated weekday name, for example, Wed
If you omit this argument, the function assumes option 1.
Returns
String. The day of the week for a given date.
Examples
The following example shows the week day values returned for a specific date: