Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subtracting Number of Days from a Date in PL/SQL [duplicate]

Tags:

sql

oracle

plsql

I would like to subtract a given x number of days from sysdate, can someone assist me on how to do that, I am using the PL/SQL language. THANKS!

like image 936
user2706266 Avatar asked Oct 22 '13 16:10

user2706266


People also ask

How do I subtract days from a date in SQL?

The DATE_SUB() function subtracts a time/date interval from a date and then returns the date.

How do you subtract days from Sysdate?

Use sysdate-1 to subtract one day from system date. Save this answer.

Can you subtract dates in SQL Oracle?

Date – dateYou can subtract a date from a date in Oracle. The result will be in days. You can also multiply by 24 to get hours and so on.

How do I calculate the number of days between two dates in PL SQL?

To count the difference between dates as days in PostgreSQL or Oracle, you simply need to subtract one date from the other, e.g. arrival - departure .


2 Answers

Use sysdate-1 to subtract one day from system date.

select sysdate, sysdate -1 from dual; 

Output:

SYSDATE  SYSDATE-1 -------- --------- 22-10-13 21-10-13  
like image 114
Abhijith Nagarajan Avatar answered Oct 15 '22 01:10

Abhijith Nagarajan


simply,

select sysdate-1 from dual 

there's a bunch more info and detail here: http://www.orafaq.com/faq/how_does_one_add_a_day_hour_minute_second_to_a_date_value

like image 43
BWS Avatar answered Oct 15 '22 00:10

BWS