Class BirtDateTime
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.
Date object. A date object that represents the start date.
Number object. The number of days to add to the date. Decimals are treated as integers, rounded down to the nearest integer.
Date object. A date that results from adding the specified number of days to the start date.
The following example adds days to a specific date:
The following example adds 15 days to each date value in the InvoiceDate field:
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.
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).
Number object. The number of hours to add to the date.
Date object. A date that results from adding the specified number of hours to the start date.
The following example adds hours to a specific date and time:
endDate = BirtDateTime.addHour( startDate, -8 ); // returns Dec 31, 2008 7:00 AMThe following example adds 36 hours to each date value in the StartTime field:
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.
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).
Number object. The number of minutes to add to the date.
Date object. A date that results from adding the specified number of minutes to the start date.
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.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.
Date object. A date object that represents the start date.
Number object. The number of months to add to the date. Decimals are treated as integers, rounded down.
Date object. A date that results from adding the specified number of months to the start date.
The following example adds months to a specific date:
The following example adds 10 months to each date value in the InvoiceDate field:
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.
A date object that represents the start date.
Number object. The number of quarters to add to the date.
Date object. A date that results from adding the specified number of quarters to the start date.
The following example adds quarters to a specific date:
The following example adds 2 quarters to each date value in the ForecastClosing field:
BirtDateTime.addSecond
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.
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).
Number object. The number of seconds to add to the date.
Date object. The result from adding the specified number of seconds to the start date.
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.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.
A date object that represents the start date.
Number Object. The number of weeks to add to the date.
Date object. A date that results from adding the specified number of weeks to the start date.
The following example adds weeks to a specific date:
The following example adds 2 weeks to each date value in the InvoiceDate field:
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.
A date object that represents the start date.
Number object.The number of years to add to the date. Decimals are treated as integers, rounded down.
A date that results from adding the specified number of years to the start date.
The following example adds years to a specific date:
The following example adds 5 years to each date value in the HireDate field:
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.
Date object. A date object from which to get the day.
An integer that represents the day of the month for a given date.
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:
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.
A date object that represents the start of the time span.
A date object that represents the end of the time span.
Integer. The number of days between two dates.
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:
BirtDateTime.diffHour
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).
A date object that represents the start of the time span.
A date object that represents the end of the time span.
Integer. The number of hours between two dates.
The following example returns the number of hours between specific dates:
// returns 36. Because the first date does not have a time, midnight is assumed.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:
BirtDateTime.diffMinute
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).
A date object that represents the start of the time span.
A date object that represents the end of the time span.
Integer. The number of minutes between two dates.
The following example returns the number of minutes between specific dates:
// returns 720. Because the first date does not have a time, midnight is assumed.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:
BirtDateTime.diffMonth
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.
A date object that represents the start of the time span.
A date object that represents the end of the time span.
Integer. The number of months between two dates.
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:
BirtDateTime.diffMonth( row["ProjectStart"], row["ProjectComplete"] )BirtDateTime.diffQuarter
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.
A date object that represents the start of the time span.
A date object that represents the end of the time span.
Integer. The number of quarters between two dates.
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:
BirtDateTime.diffQuarter( row["ProjectStart"], row["ProjectComplete"] )BirtDateTime.diffSecond
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).
A date object that represents the start of the time span.
A date object that represents the end of the time span.
Integer. The number of seconds between two dates.
The following example returns the number of seconds between specific dates:
// returns 3600. Because the first date does not have a time, midnight is assumed.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:
BirtDateTime.diffWeek
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 1 week, even though only three days separates the two dates.
A date object that represents the start of the time span.
A date object that represents the end of the time span.
Integer. The number of weeks between two dates.
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:
BirtDateTime.diffYear
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.
A date object that represents the start of the time span.
A date object that represents the end of the time span.
Integer. The number of years between two dates.
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:
BirtDateTime.diffYear
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.
A date object that represents the start of the time span.
A date object that represents the end of the time span.
Integer. The number of years between two dates.
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:
BirtDateTime.firstDayOfMonth
This function returns the date for the first day of the month in which the input date falls.
A date object from which to get the month.
Date object. The first day of the month for a given date.
The following example shows the month values returned for a specific date:
BirtDateTime.firstDayOfQuarter
This function returns the date for the first day of the quarter in which the input date falls.
A date object from which to get the quarter.
Date object. The first day of the quarter for a given date.
The following example shows the quarter values returned for a specific date:
BirtDateTime.firstDayOfWeek
This function returns the date for the first day of the Week in which the input date falls, which is always a Sunday.
A date object from which to get the Week.
Date object. The first day of the Week for a given date.
The following example shows the Week values returned for a specific date:
BirtDateTime.firstDayOfYear
This function returns the date for the first day of the Year in which the input date falls.
A date object from which to get the Year.
Date object. The first day of the Year for a given date.
The following example shows the Year values returned for a specific date:
BirtDateTime.month
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.
A date object from which to get the month.
Integer. 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.
String. The month for a given date.
The following example shows the month values returned for a specific date:
The following example returns the month for the current date:
BirtDateTime.now
This function returns the current date and time, for example, Feb 2, 2009 2:05 PM.
Date object. The current date and time.
The following example returns the number of hours from the current date and time to Christmas:
BirtDateTime.quarter
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.
A date object from which to get the quarter number.
Integer. The quarter number for a given date.
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:
BirtDateTime.today
This function returns the current date that includes a time value of midnight, for example, Feb 2, 2009 12:00 AM.
Date object. The current date with a time value of midnight.
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.
BirtDateTime.week
This function returns a number from 1 to 52 that represents the week number for a given date.
A date object from which to get the week number.
Integer. The week number for a given date.
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:
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.
A date object from which to get the day of the week.
Integer. 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.
String. The day of the week for a given date.
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:
BirtDateTime.year
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.
A date object from which to get the year.
Integer. The four-digit year value for a given date.
The following example returns the year for each value in the HireDate field:
The following example returns the year for the current date:
(c) Copyright Actuate Corporation 2012 |