## Difference between two dates

Solved
Occasional Contributor
Posts: 15

# Difference between two dates

Hello!

I'm trying to calculate the difference between two dates but i don't want to take into account Sundays, how can this be done?

eg. Say i'm trying to find the days between March, 2nd and March, 9th; the output should be '6'.

Any help will be much appreciated.

Greets,

Accepted Solutions
Solution
‎03-30-2017 04:41 PM
Super User
Posts: 13,941

## Re: Difference between two dates

```data example;
days = intck('weekday1W','02MAR2017'd,'09MAR2017'd);
run;```

the weekday1w interval with the intck function considers a week to be six days with Sunday as a weekend day.

All Replies
Super User
Posts: 8,218

## Re: Difference between two dates

[ Edited ]

Note: The following is really @ballardw's suggestion, but the system wouldn't let me delete my incorrect post. I hadn't read the request sufficiently and didn't realize that only Sundays were to be excluded. Art T

Use the INTCK function. But if you want 6 days given your example, you'll have to add 1. e.g.:

```data have;
informat date1 date2 date9.;
input date1 date2;
dif=INTCK('WEEKDAY1W',date1,date2,'C');
cards;
02mar2017 09mar2017
24feb2017 09mar2017
;
```

Art, CEO, AnalystFinder.com

PROC Star
Posts: 311

Super User
Posts: 6,934

## Re: Difference between two dates

There's probably a short way, but here's the long way.

data want;

set have;

n_days = 0;

do i=date1 to date2;

if weekday(i) ne 1 then n_days + 1;

end;

if weekday(date1) > 1 or weekday(date2) > 1 then n_days = n_days - 1;

run;

There are various ways to count, depending on whether or not the starting date is a Sunday or the ending date is a Sunday.  The last line in the program is just one way to account for that.  You may want to set up your own rules.

PROC Star
Posts: 311

## Re: Difference between two dates

I don't know if there's a slicker/more efficient solution, but this is what I'd do. Adjust the end value if you want it to be inclusive of that date. I had to put the -1 to get your desired result.

``````
data want;
start = '02MAR2017'd;
end = '09MAR2017'd;
do i = start to end -1;
all_cnt + 1;
non_sunday_cnt + (weekday(i) ne 7);
end;
run;``````
Solution
‎03-30-2017 04:41 PM
Super User
Posts: 13,941

## Re: Difference between two dates

```data example;
days = intck('weekday1W','02MAR2017'd,'09MAR2017'd);
run;```

the weekday1w interval with the intck function considers a week to be six days with Sunday as a weekend day.

Super User
Posts: 8,218

## Re: Difference between two dates

A nice list of the available intervals that can be used with the intck function can be found at: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003065889.htm

Art, CEO, AnalystFinder.com

☑ This topic is solved.