Ahlam Mustafa
Ahlam Mustafa

Reputation: 11

subtracting numeric fields from a date field

i have a tenure field (numeric) on a table representing the number of months a user has been on file. I want to subtract that field from today's date to return the registration date of the user. Any idea how to do this using oracle sql

Upvotes: 0

Views: 83

Answers (2)

Boneist
Boneist

Reputation: 23588

Something like:

add_months(sysdate, -your_number_of_months_column)

? You may possibly want to use trunc(sysdate).

However, it sounds like a bad design; why is the registration date of the user not stored in its own column? If you select the user's record today, the registration date will be different than if you selected it tomorrow (unless you use trunc(sysdate, 'mm')).

Upvotes: 1

paul
paul

Reputation: 22001

ADD_MONTHS(SYSDATE, -1 * tenureMonths)

Upvotes: 0

Related Questions