Reputation: 1726
I've got a Crystal Report (2011) that uses a Stored Procedure to display some data. One of the fields is TimeSpent (bigint) and it holds the number of Ticks in a TimeSpan (in C#, we pass TimeSpan.Ticks to the DB to be stored).
Obviously on my report I wouldn't want to show this, so I am wondering how I can convert ticks to read dd:hh:mm:ss
, e.g. 01:05:58:25
for 1 day, 5 hours, 58 minutes and 29 seconds
?
Upvotes: 1
Views: 496
Reputation: 7287
A tick is 100 nanoseconds, or 10 million ticks per second. So first convert to seconds
numbervar span := {field.ticks}/10000000;
From there, just break the seconds down into time pieces (This snippet is from tek-tips):
numbervar days;
numberVar hrs;
numberVar min;
numberVar sec;
stringVar ddhhmmss;
days:= Truncate(Truncate(Truncate(span/60)/60)/24);
hrs := Remainder(Truncate(Truncate(span/60)/60),24);
min := Remainder(Truncate(span/60),60);
sec := Remainder(span,60);
ddhhmmss := totext(days,0,"") + ":" + totext(hrs,"00") + ":" + totext(min,"00") + ":" + totext(sec,"00");
ddhhmmss
Upvotes: 1