w3resource

Oracle: First and last day of the current year

Oracle Datetime: Exercise-5 with Solution

Write a Oracle SQL statement to get the first and last day of the current year.

Sample Solution:

Oracle Code:

SELECT TRUNC (SYSDATE, 'YEAR') "First Day of the year" FROM DUAL;
SELECT ADD_MONTHS (TRUNC (SYSDATE, 'YEAR'), 12) - 1 "Last Day of the Year" FROM DUAL;

Output:

  	First Day of the year
1	1/1/2021 12:00:00 AM

  	Last Day of the Year
1	12/31/2021 12:00:00 AM

Improve this sample solution and post your code through Disqus.

Previous: Write a Oracle SQL statement to determine how many days are left in the current month.
Next: Write a Oracle SQL statement to get the number of days in current month.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.