Write a PL/SQL anonymous block which will perform date and time operations. Declare a variable ‘d’ of type DATETIME and initialize with the value '25-Jan-2020'. And then perform below date and time operations and print the result:1. Print the date after adding 4 months to the date d2. Print only the year part present in the date d3. Print the last day of the month based on the date d4. Assume that the current date is ‘2020-10-25’. Display the number of month between the current date and the date d
Question
Write a PL/SQL anonymous block which will perform date and time operations. Declare a variable ‘d’ of type DATETIME and initialize with the value '25-Jan-2020'. And then perform below date and time operations and print the result:1. Print the date after adding 4 months to the date d2. Print only the year part present in the date d3. Print the last day of the month based on the date d4. Assume that the current date is ‘2020-10-25’. Display the number of month between the current date and the date d
Solution 1
Here is the PL/SQL anonymous block that performs the requested date and time operations:
DECLARE
d DATE := TO_DATE('25-Jan-2020', 'DD-Mon-YYYY');
current_date DATE := TO_DATE('2020-10-25', 'YYYY-MM-DD');
months_between INTEGER;
BEGIN
-- 1. Add 4 months to the date d and print
DBMS_OUTPUT.PUT_LINE('Date after adding 4 months: ' || TO_CHAR(ADD_MONTHS(d, 4), 'DD-Mon-YYYY'));
-- 2. Print only the year part present in the date d
DBMS_OUTPUT.PUT_LINE('Year part of the date: ' || TO_CHAR(d, 'YYYY'));
-- 3. Print the last day of the month based on the date d
DBMS_OUTPUT.PUT_LINE('Last day of the month: ' || TO_CHAR(LAST_DAY(d), 'DD-Mon-YYYY'));
-- 4. Display the number of month between the current date and the date d
months_between := MONTHS_BETWEEN(current_date, d);
DBMS_OUTPUT.PUT_LINE('Number of months between current date and d: ' || months_between);
END;
/
This block declares a date variable d and initializes it with '25-Jan-2020'. It also declares a current_date variable and initializes it with '2020-10-25'. Then it performs the following operations:
- Adds 4 months to
dand prints the result. - Extracts and prints the year part of
d. - Finds and prints the last day of the month based on
d. - Calculates and prints the number of months between
current_dateandd.
Solution 2
Here is the PL/SQL anonymous block that performs the requested date and time operations:
DECLARE
d DATE := TO_DATE('25-Jan-2020', 'DD-Mon-YYYY');
current_date DATE := TO_DATE('2020-10-25', 'YYYY-MM-DD');
months_between INTEGER;
BEGIN
-- 1. Add 4 months to the date d and print
d := ADD_MONTHS(d, 4);
DBMS_OUTPUT.PUT_LINE('Date after adding 4 months: ' || TO_CHAR(d, 'DD-Mon-YYYY'));
-- 2. Print only the year part present in the date d
DBMS_OUTPUT.PUT_LINE('Year part of the date: ' || TO_CHAR(d, 'YYYY'));
-- 3. Print the last day of the month based on the date d
DBMS_OUTPUT.PUT_LINE('Last day of the month: ' || TO_CHAR(LAST_DAY(d), 'DD-Mon-YYYY'));
-- 4. Display the number of month between the current date and the date d
months_between := MONTHS_BETWEEN(current_date, d);
DBMS_OUTPUT.PUT_LINE('Number of months between current date and date d: ' || months_between);
END;
/
This block declares a date variable d and initializes it with '25-Jan-2020'. It then performs the following operations:
- Adds 4 months to
dand prints the result. - Prints the year part of
d. - Prints the last day of the month based on
d. - Calculates and prints the number of months between the current date and
d.
Similar Questions
Write a PL/pgSQL block to find out count of completed month between two dates enter by the user.
Write a PL/SQL simple procedure named display_dates with 2 input parameter. The first input parameter is d1 of type date. The second input parameter is d2 of type date. This procedure will display the dates between d1 and d2(exclusive), each in a newline.Use the below skeleton:Procedure name: display_datesInput parameter: d1 of type date, d2 of type dateNote:Do not change the procedure nameDo not change the argument count and orderDo not change the output text.Instructions:1. Create the procedure successfully2. Once the procedure is created, check the functionality of the procedure using different anonymous block call.3. DO NOT submit the anonymous block. Submit only the CREATE PROCEDURE query.
Write a JAVA program in which take date(DDMMYYYY) from user and displaynext day date(DDMMYYYY) as output.Example:Input: date=09, month=-06, year=1992Output: date=10, month=-06, year=1992Note:-1. Consider condition for leap year2. Consider number of days in month of February based on leap year ( if leapyear then February days =29, else days = 28 ) )3. Consider number of days either 30 or 31 based on month entered by user
Create a class called Date that includes three pieces of information as instance variables—a month, a day and a year. Your class should have a constructor that initializes the three instance variables after validating the given date. Provide a getDetails() member method to read the date. Provide a method displayDate() that displays the month, day and year separated by forward slashes(/). Write a C++ application and pseudocode that demonstrates classDate’s capabilities.Input : Read Month, Day and Year (Line by line)Output :Print Date that displays the month, day and year separated by forward slashes(/)Note: print "Invalid Date" other than the following2000 < Year < 20250 < Day <= 31 ( for the months Jan, March, May, July, August, October, December)0 < Day <= 30 ( for the months April, June, September, and November)0 < Day <= 28 ( for the month February ) and (0 < Day <= 29), if month = 2 and year = leap year0 < Month < = 12
Write a C program that prompts the user to enter the date as three integer values for the month, the day in the month, and the year. The program should then output the date in the form 31st December 2010 when the user enters 12 31 2010, say. The program has to work out when superscripts “th”, “nd”, “st”, and “rd” need to be appended to the day value. The programmer should not forget 1st, 2nd, 3rd, 4th; and then 11th, 12th, 13th, 14th; and 21st, 22nd, 23rd, and 24th.Testcases:Input:02 11 2021Output:11th February 202
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.