Fluorite | Level 6

## Calculate diffrence between two DateTime fields in SAS VA

Hello All

I have two dates in following format

Date 1 - December 11, 2018 05:15:20PM

Date 2 - January 21, 2018 01:25:21AM

How can i calculate difference between these two date in HOURS ?

7 REPLIES 7
Tourmaline | Level 20

## Re: Calculate diffrence between two DateTime fields in SAS VA

``````
data test;
char_Date1='December 11, 2018 05:15:20PM';
Num_date1=input(char_Date1,anydtdtm32.);
char_Date2='January 21, 2018 01:25:21AM';
Num_date2=input(char_Date2,anydtdtm32.);
Difference=abs(intck('DTHOUR',Num_date1,Num_date2));
format num_date: datetime20.;
run;``````
Fluorite | Level 6

## Re: Calculate diffrence between two DateTime fields in SAS VA

Hello Novinosrin

Thanks for the reply..What i am asking is simple function in SAS Visual Analytics to get the output.

This programe cannot possible to write in SAS VA
Tourmaline | Level 20

## Re: Calculate diffrence between two DateTime fields in SAS VA

Oh I blame the damn!!!!!!!!!!!!!!!!! Dunkin Coffee(still not waking me up) that my eyes didn't even notice the VA in the question. My apologies. Best is to wait for somebody who knows VA to respond. Sorry about that.

Fluorite | Level 6

## Re: Calculate diffrence between two DateTime fields in SAS VA

I am having the same issue but my datetime fields are formatted as 07OCT2018:10:14:00.00. Can you provide a solution for me?
Tourmaline | Level 20

## Re: Calculate diffrence between two DateTime fields in SAS VA

Hi @JanSanford  I'm afraid I do not work with  SAS VA. Are you expecting a solution in  SAS VA?

Fluorite | Level 6

## Re: Calculate diffrence between two DateTime fields in SAS VA

Oops. No. Am using base SAS.
PROC Star

## Re: Calculate diffrence between two DateTime fields in SAS VA

Datetimes are stored as seconds. You could just subtract one from the other then divide by 3,600 to convert to hours.

Discussion stats
• 7 replies
• 1190 views
• 4 likes
• 4 in conversation