- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I want to calculate difference in minutes between two datetime fields.
I want to calculate difference in seconds between two datetime fields.
my calculation provide wrong results:
INTCK('minute',application_DateTime,Loan_datetime)
INTCK('seconds',application_DateTime,Loan_datetime)
data have;
format Loan_DateTime Application_DateTime datetime20.;
input Loan_DateTime ::datetime18. Application_DateTime ::datetime18.;
cards;
01SEP2023:09:59:00 01SEP2023:09:58:16
;
Run;
data want;
set have;
dif_minutes=INTCK('minutes',Application_DateTime,Loan_DateTime);
dif_seconds=INTCK('seconds',Application_DateTime,Loan_DateTime);
Run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Let's say you have a difference of 90 seconds between the two timestamps. There are a variety of ways to express that, including (but not limited to):
90 seconds
1 minute 30 seconds
1.5 minutes
01:30
So variable names are up to the programmer. What you want is up to you. When I looked at the problem, I thought the second expression was what you were asking for. So I chose DURATION as the top version (90 seconds) and used it in the calculations to obtain the numbers in the second line (1 minute, 30 seconds). But if that is not your preference, you can fiddle with it pretty easily.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Not following you, they are the same value, so difference should be 0...?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
sorry I wrote wrong date time values.
Anyway,I saw the correct way to do it:
for dif in seconds need to substract the two datetimes
for dif in minutes need to use INTCK
For
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your datetime fields are already measured in seconds. So you could use:
duration = Application_DateTime - Loan_DateTime;
dif_in_minutes = int(duration / 60);
dif_in_seconds = duration - 60*dif_in_minutes;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I saw that difference in seconds is calculated by:
Application_DateTime - Loan_DateTime;
Why did you call it duration and what is the difference between duration and dif_in_seconds?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Let's say you have a difference of 90 seconds between the two timestamps. There are a variety of ways to express that, including (but not limited to):
90 seconds
1 minute 30 seconds
1.5 minutes
01:30
So variable names are up to the programmer. What you want is up to you. When I looked at the problem, I thought the second expression was what you were asking for. So I chose DURATION as the top version (90 seconds) and used it in the calculations to obtain the numbers in the second line (1 minute, 30 seconds). But if that is not your preference, you can fiddle with it pretty easily.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Question1-
What is the way to calculate the complete number of minutes difference between two datetimes via INTCK?
In this example should get "1" but with my INTCK I got "2"?
data have;
format Loan_DateTime Application_DateTime datetime20.;
input Application_DateTime ::datetime18. Loan_DateTime ::datetime18.;
cards;
01SEP2023:09:57:16 01SEP2023:09:59:00
;
Run;
/**Note-datetime fields are already measured in seconds**/
Data want;
set Have;
duration_in_seconds=Loan_DateTime-Application_DateTime ;/***104 seconds**/
/*altenative way :duration_in_seconds=intck('seconds',Application_DateTime,Loan_DateTime);*/
dif_in_minutes = int(duration_in_seconds / 60); /**1 minute**/
dif_in_seconds = duration_in_seconds - 60*dif_in_minutes;/**44 seconds***/
/*Dont USE this calc-intck('minutes',Application_DateTime,Loan_DateTime);*/
Run;
Question2-
Let's say that I want to show difference in minutes but also partial minutes.
So difference between 01SEP2023:09:57:16 and 01SEP2023:09:59:00 should get 1.73 (since 44 seconds divide by 60).
What is the way to calculate it please?
Here I found the solution
duration_in_seconds=Loan_DateTime-Application_DateTime ;/***104 seconds**/
duration_in_minutes=duration_in_seconds/60;/***1.73***/
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content