Professional Documents
Culture Documents
TIMESTAMPADD(SQL_TSI_DAY,DAY_OF_QUARTER(CURRENT_DATE)*(1)+1, CURRENT_D
ATE)
This was included to show the calculations discussed above can be used with other
functions. This is the same expression as the one that returns the first day of the current month
except this one uses the DAY_OF_QUARTER property to return the first day of the current
quarter.
Last Day of the Previous Month
TIMESTAMPADD(
SQL_TSI_DAY
,
-(1),TIMESTAMPADD(
SQL_TSI_DAY
,DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))
From right to left the first TIMESTAMPADD returns the first day of the Current Month. The
second TIMESTAMPADD subtracts a month to arrive at the first day of the previous month.
Last Day of Current Month
TIMESTAMPADD(
SQL_TSI_DAY
,
-(1),TIMESTAMPADD(
SQL_TSI_MONTH
,
1,TIMESTAMPADD( SQL_TSI_DAY ,DAYOFMONTH( CURRENT_DATE) * -(1) +
1, CURRENT_DATE)))
From right to left the first TIMESTAMPADD finds the first day of the current Month. The second
TIMESTAMPADD adds one month to the date to arrive at the first day of the next month. The
final TIMESTAMPADD subtracts one day from the returned date to arrive at the last day of the
Current Month.
Last Day of the Next Month
TIMESTAMPADD(
SQL_TSI_DAY
,
-(1),TIMESTAMPADD(
SQL_TSI_MONTH
,
2,TIMESTAMPADD( SQL_TSI_DAY ,DAYOFMONTH( CURRENT_DATE) * -(1) +
1, CURRENT_DATE)))
From right to left the first TIMESTAMPADD finds the first day of the current Month. The second
TIMESTAMPADD adds two months to the date to arrive at the first day of month after next. The
final TIMESTAMPADD subtracts one day from the returned date to arrive at the last day of the
Next Month.
Last Day of Previous Year
TIMESTAMPADD(
SQL_TSI_DAY
,
-1,TIMESTAMPADD(
SQL_TSI_DAY
,EXTRACT( DAY_OF_YEAR FROMCURRENT_DATE) * -(1) + 1,CURRENT_DATE))
From right to left the first TIMESTAMPADD returns the first day of the current year. The second
TIMESTAMPADD subtracts one day to arrive at December 31st of the previous year.
Last Day of Current Year
TIMESTAMPADD(SQL_TSI_YEAR, 1, TIMESTAMPADD( SQL_TSI_DAY , -1,TIMESTAMPADD(
SQL_TSI_DAY
,EXTRACT(
DAY_OF_YEAR FROMCURRENT_DATE)
*
-(1)
+
1,CURRENT_DATE)))
From right to left the first TIMESTAMPADD returns the first day of the current year. The second
TIMESTAMPADD deducts one day to arrive at December 31 of the previous year. The third
TIMESTAMPADD adds a single year to the date to arrive at December 31 of the Current Year.