Contributor
Posts: 53

# expressing minutes as a fraction

Is there an easy and straightforward way to express a datetime value as a fraction? For example 1:15PM would be 1.25

PROC Star
Posts: 8,165

## Re: expressing minutes as a fraction

Since time is just the number of seconds since midnight, you just have to divide by 60*60.  Although, doing that would give you 13.25 rather than 1.25, but would allow you to differentiate between 1:15am and 1:15pm.

e.g.:

data have;

informat dt anydtdtm21.;

input dt;

fraction=timepart(dt)/(60*60);

cards;

28nov2012:01:15:00

28nov2012:13:30:00

;

Occasional Contributor
Posts: 8

## Re: expressing minutes as a fraction

This worked closer to my problem without the formatting:

NOTE.  My field "Hours" was formatted as time5.

So....

data crsefile;

set crsefile;

hoursdec=timepart(hours)/(60*60);

run;

So hours 1:55 became 1.9166666667

Super User
Posts: 13,583

## Re: expressing minutes as a fraction

or fractiontime = hour(datetimevariable) + minute(datetimevariable)/60;

if you don't want hour 13 to 23, ignoring AM/Pm

fractiontime = mod(hour(datetimevariable),12) + minute(datetimevariable)/60;