Barite | Level 11

## Interval in minutes between datetimes

Why is SAS doing this? It is obviously wrong:

t = intck('min', date1, date2);

date1 is 18feb2023 12:59

date2 is 18feb 2023 13:20

The interval should be 21 minutes, but I am getting -699 minutes.

I understand it is confused by the military time, but what is the explanation and how to work around this?

Any thoughts are welcome!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Interval in minutes between datetimes

Check the actual values of DATE1 and DATE2.  The values you showed are 21 minutes apart.

``````data test;
date1 ='18feb2023 12:59'dt;
date2 ='18feb2023 13:20'dt;
diff1 = intck('min',date1,date2);
diff2 = intck('min',date1,date2,'c');
diff3 = (date2-date1)/60;
format date1 date2 datetime19.;
run;
proc print;
run;
``````
```Obs                  date1                  date2    diff1    diff2    diff3

1      18FEB2023:12:59:00     18FEB2023:13:20:00      21       21       21
```

To get -699 minutes you would have had to mistakenly coded the second date as 1:20 AM instead of 1:20 PM.

``````data test;
date1 ='18feb2023 12:59'dt;
date2 ='18feb2023 13:20'dt;
date3 = date1 - 699*60;
diff1 = intck('min',date1,date2);
diff2 = intck('min',date1,date2,'c');
diff3 = (date2-date1)/60;
format date1-date3 datetime19.;
run;``````

2 REPLIES 2
Super User

## Re: Interval in minutes between datetimes

Check the actual values of DATE1 and DATE2.  The values you showed are 21 minutes apart.

``````data test;
date1 ='18feb2023 12:59'dt;
date2 ='18feb2023 13:20'dt;
diff1 = intck('min',date1,date2);
diff2 = intck('min',date1,date2,'c');
diff3 = (date2-date1)/60;
format date1 date2 datetime19.;
run;
proc print;
run;
``````
```Obs                  date1                  date2    diff1    diff2    diff3

1      18FEB2023:12:59:00     18FEB2023:13:20:00      21       21       21
```

To get -699 minutes you would have had to mistakenly coded the second date as 1:20 AM instead of 1:20 PM.

``````data test;
date1 ='18feb2023 12:59'dt;
date2 ='18feb2023 13:20'dt;
date3 = date1 - 699*60;
diff1 = intck('min',date1,date2);
diff2 = intck('min',date1,date2,'c');
diff3 = (date2-date1)/60;
format date1-date3 datetime19.;
run;``````

Barite | Level 11

## Re: Interval in minutes between datetimes

Yes, this is exactly what happened, thank you!
Discussion stats
• 2 replies
• 415 views
• 1 like
• 2 in conversation