Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...your web site's great! I've been using this system for almost a year now and find it really, really helpful. The people have been helpful in answering just about any question you post in the forums..."

Geography

Where in the world do Tek-Tips members come from?
DEU (IS/IT--Management)
18 Jan 02 3:27
hello all,

does anyone know of a way to find difference between two dates in
terms of days, months and so on. I will like to find out no. of months
between two given dates. Is that possible.

TIA

deu
OraCool (TechnicalUser)
18 Jan 02 8:43
Hi Deu,

Teradata has a view called Sys_Calendar.Calendar.

This has many good attributes and can be easily used to solve your problem.

type 'show view sys_calendar.calendar;' to see the attributes or 'help view sys_calendar.calendar' to get an explanation of the attributes.

Check it out, if you need more info give me an example and I will try and write a sql script to solve it for you.

Regards
DEU (IS/IT--Management)
20 Jan 02 23:01
Heloo OraCool,

Thanks for ur reply. Suppose i have two dates say 10th Dec 2001 and 14th Jan 2002 i need to find the no of months between these two dates which is 1 whereas if the given dates are 10th Dec 2001 and 4th Jan 2002 it should be 0 coz it hasn't come to 10th Jan to be exactly one month. I need this routine to update the no. of payment dues for customers on a daily basis in a given table. Any help will be highly appreciated.

Warm Regards

Deu
rohitrevo (TechnicalUser)
21 Jan 02 3:23
Hi Deu

Teradata has the facility of doing simple arithmetic sums or subtractions on date functions and it returns number of days as output.

Assuming we have a table datetest and we want a list of customers where  difference between dtofpay and dtofjoin is greater than 30 days or 1 month.

sel * from datetest;

 *** Query completed. 3 rows found. 3 columns returned.
 *** Total elapsed time was 1 second.

    cust_id  dtofjoin   dtofpay
-----------  --------  --------
         30  01/11/24  02/01/12
         20  01/12/24  02/01/12
         10  01/12/10  01/12/11

The following SQL will work

sel * from datetest where (dtofpay-dtofjoin) > 30;

 *** Query completed. One row found. 3 columns returned.
 *** Total elapsed time was 1 second.

    cust_id  dtofjoin   dtofpay
-----------  --------  --------
         30  01/11/24  02/01/12
OraCool (TechnicalUser)
21 Jan 02 8:40
Hi Deu

I guess Rohit's suggestion works for you, if you need more on that please let me know.

Regards
tdatgod (Programmer)
21 Jan 02 15:59
Hi,
   It depends on what version of Teradata you are running.  Given the above example will return the number of DAYS between the 2 dates.

Teradata now supports the ANSI Interval specifier.

sel ( date1 - date2 ) month(4);

This tell Teradata you want the answer as an INTERVAL MONTH.

Unfortunately the (4) is the number of DIGITS you want in your answer.   This limits the maximum number of months in the specification to 9999 months ( or about 27 years ).  

This is a limit imposed by Teradata because we use the same parse routine for Years and Months and ANSI limits years to (4) or 9999 years.

I have a request in to up this limit for MONTHS.

please see   

    Thread328-150396

for a further explanation of the interval specification.

If you exceed the number of digits you will get an error
saying date overflow.  for example

   sel date - ( date - 365)) month(1);

would overflow because 12 can't fit in 1 digit (0-9).


Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close