turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- BI
- /
- Enterprise Guide
- /
- How to calculate time difference (minutes) between...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-06-2008 08:42 AM

I have two datetime fields and want to calculate the difference in minutes between the two fields. I don't believe the DATDIF function will return minutes, will it? Is there another function that I can use? So far I haven't had any luck searching the SAS EG help or the web....

Thanks in advance.

Thanks in advance.

Accepted Solutions

Solution

07-26-2016
01:33 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-06-2008 04:18 PM - last edited on 07-26-2016 01:33 PM by ChrisHemedinger

mdavidson wrote:

got it: INTCK('minute',field1,field2 )

INTCK can give results that aren't what you want in all cases, as it counts from the beginning of the interval (see the Details section of the documentation). If your data are recorded to the minute, it won't matter. If your data are recorded to the second, it might.

As datetime variables are recorded in seconds, an alternative is to use the fact that there are 60 seconds in a minutes and just do the arithmetic directly

(datetime2 - datetime1)/60 provides minutes with decimal fractions.

FLOOR( (datetime2 - datetime1)/60 ) provides the whole minute durations.

For instance, 12:01:50 to 12:02:10 is 1 using INTCK, 0.333 using the decimal minutes, and 0 using the FLOOR version.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-06-2008 09:32 AM

Got it: INTCK('minute',field1,field2 )

Solution

07-26-2016
01:33 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-06-2008 04:18 PM - last edited on 07-26-2016 01:33 PM by ChrisHemedinger

mdavidson wrote:

got it: INTCK('minute',field1,field2 )

INTCK can give results that aren't what you want in all cases, as it counts from the beginning of the interval (see the Details section of the documentation). If your data are recorded to the minute, it won't matter. If your data are recorded to the second, it might.

As datetime variables are recorded in seconds, an alternative is to use the fact that there are 60 seconds in a minutes and just do the arithmetic directly

(datetime2 - datetime1)/60 provides minutes with decimal fractions.

FLOOR( (datetime2 - datetime1)/60 ) provides the whole minute durations.

For instance, 12:01:50 to 12:02:10 is 1 using INTCK, 0.333 using the decimal minutes, and 0 using the FLOOR version.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-25-2010 02:17 PM

This is exactly what I wanted. Thanks very much!