## time : milliseconds

Solved
Frequent Contributor
Posts: 75

# time : milliseconds

i have a variable of time, such as 08:25:46.87. i need to find difference between two times and want to know total milliseconds.

i found function INTCK, but i don't have there milliseconds.

what i should do?

what do you thins about the next solution : if i got that difference between two times is : 00:02:37.44, i can convert minutes to seconds and get total seconds 157 and to multiply it by 1000(1 seconds=1000milliseconds), and then add 440 seconds(44*1000/100)?

thank you

Accepted Solutions
Solution
‎11-03-2015 11:48 AM
Super User
Posts: 23,724

## Re: time : milliseconds

Not quite.

Duration_Seconds = End_Time - Start_Time;
Duration_Milliseconds = Duration_Seconds*1000;

Format Duration_Seconds Duration_Milliseconds 12.;

The duration variable will be in seconds so you need to subtract and multiply by 1000. Don't overthink it

All Replies
Super User
Posts: 8,111

## Re: time : milliseconds

Time is stored as the number of seconds since midnight.  If you have milliseconds or other fractions of a second then they will be there as the fractional part of the number.  To find the difference between two times just subtract them.

A-B

To express the result in millisecond just mulitple by 1,000.

Frequent Contributor
Posts: 75

## Re: time : milliseconds

thank you.  as i understand you, the number after dot, is number of seconds and not milliseconds and the maximum can be 100.(i never see more than 100). i have to substract only two numbers, and the result multiply  by 1000?

for example :

1. 08:20:41.87

1. 08:20:40.47

08:20:41.87-08:20:40.47=00:00:01.40(one seconds and 41 number of seconds)

(40/100+01)*1000? right?

thank you

Solution
‎11-03-2015 11:48 AM
Super User
Posts: 23,724

## Re: time : milliseconds

Not quite.

Duration_Seconds = End_Time - Start_Time;
Duration_Milliseconds = Duration_Seconds*1000;

Format Duration_Seconds Duration_Milliseconds 12.;

The duration variable will be in seconds so you need to subtract and multiply by 1000. Don't overthink it
Super User
Posts: 8,111

## Re: time : milliseconds

If you did not collect milliseconds then you probably do not have them. But perhaps you are just seeing two decimal places because of the format attached to the variable.

data _null_;
t1= '08:20:41.87't ;
t2= '08:20:40.47't ;
s = t1-t2 ;
ms = s*1000;
put (t1 t2 s) (= time12.3 /);
put (t1 t2 s ms) (= /);
run;
t1=8:20:41.870
t2=8:20:40.470
s=0:00:01.400

t1=30041.87
t2=30040.47
s=1.4
ms=1400

Super User
Posts: 13,542

## Re: time : milliseconds

Displayed values really depend on the format. If you use a datetime with no decimal part you won't see any fraction of a second.

Look in the log at the results of this example with different formats.

data _null_;
x = "10JAN2015:10:15:23.123456"dt;
put x datetime22.;
put x datetime22.1;
put x datetime22.2;
put x datetime22.3;
put x datetime22.4;
put x datetime22.5;

run;
🔒 This topic is solved and locked.