Skip to content

print format for difftime

4 messages · BXC (Bendix Carstensen), Peter Dalgaard, Gabor Grothendieck

#
Has anyone written a function that will print a difftime in the form:

hh:mm:ss

or

yy-mm-dd hh:mm:ss

depending on the actual size.
(sloppy notation for months/minutes, but surely you get the point).

Bendix
----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
bxc at steno.dk
www.biostat.ku.dk/~bxc
#
"BXC (Bendix Carstensen)" <bxc at steno.dk> writes:
Ummm, how are you going to convert a number of days to
years/months/days without specifying an origin? (00-01-00 could be
28,29,30, or 31 days.) Unless, of course you want to deal in "banker's
months" of 30 + 5.25625/12 days.
#
On 5/21/05, BXC (Bendix Carstensen) <bxc at steno.dk> wrote:
Assuming your difftime, dd, represents time since the Epoch,
convert it to units of days, dd.day, and then use chron or times
depending on whether or not its one day or more.

library(chron)
zero <- structure(0, units = "secs", class = "difftime")
dd.day <- as.vector((dd + zero)/(24*60*60))
if (dd.day < 1) times(dd.day) else chron(dd.day)
#
Peter Dalgaard <p.dalgaard at biostat.ku.dk> writes:
Doh. Make that 5.2425 (97 leap days per 400 years). What was I
thinking of there?