Solved

# How to calc minutes to Week - Days- Hours- Min of a working 1 days = 8 hours en 40 hours = 1 week

Posted on 2006-06-22
265 Views
Hoi,

I have make somthing, but it wont work correcly.

inttotimestr(2123333) = result 73d 05:43:04:53 ????????

function inttotimestr(S: integer): string;   // z.B. 3600-> '01:00:00'
var
st:string;
ti,t:integer;
begin

try
st:='';
if (s > 28800) then begin
st:=inttostr(s div 28800)+'d ';
end;
s:=s mod 28800;

if (s div 480) = 0 then
st:=st+'00:'
else if (s div 480) < 10 then
st:=st+'0'+inttostr(s div 480)+':'
else
st:=st+inttostr(s div 480)+':';

ti:=s mod 480;
if (ti div 60) = 0 then
st:=st+'00:'
else if (ti div 60) < 10 then
st:=st+'0'+inttostr(ti div 60)+':'
else
st:=st+inttostr(ti div 60)+':';

t:=ti mod 60;
if t = 0 then
st:=st+'00'
else if t < 10 then
st:=st+'0'+inttostr(t)
else
st:=st+inttostr(t);
except
st:='00:00:00';
end;
inttotimestr:=st;
end;

0
Question by:kuken1
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 6
• 6
• 2
• +1

LVL 28

Expert Comment

ID: 16964733
hm... you are making some errors from the start: are you talking about minutes or seconds?

here is a routine I made, because I just can't make out what you want to do. This will convert a number of minutes, to week,day, hour, minute, considering that 1 week has 5 days, 1 day has 8 hours and 1 hour has 60 seconds.

function inttotimestr(s:integer):string;// input is minutes
var w,d,h,m:word;
begin
w:=s div (5*8*60);// 5 days with 8 hours having 60 min
s:=s mod (5*8*60);
d:=s div (8*60);
s:=s mod (8*60);
h:=s div 60;
m:=s mod 60;
result:=format('%d:%.2d:%.2d:%.2d',[w,d,h,m]);
end;
0

LVL 26

Expert Comment

ID: 16964808
Example that breaks the minutes down to weeks (40 hrs) , days (8 hrs) and remaining hours:minutes:seconds

Regards,
Russell

function MinutesToWorkTime(Minutes: Integer): String;
var  dwTime:     Array [0..4] of Integer;
dwCurrent:  Integer;
begin

// Calculate weeks
dwTime[0]:=Minutes div 144000;
dwCurrent:=Minutes mod 144000;

// Calculate days
dwTime[1]:=dwCurrent div 28800;
dwCurrent:=dwCurrent mod 28800;

// Calculate hours
dwTime[2]:=dwCurrent div 3600;
dwCurrent:=dwCurrent mod 3600;

// Calculate minutes
dwTime[3]:=dwCurrent div 60;
dwCurrent:=dwCurrent mod 60;

// Calculate seconds
dwTime[4]:=dwCurrent;

// Set result
SetLength(result, 0);

// Build string with weeks and days
if (dwTime[0] > 0) then result:=IntToStr(dwTime[0])+'w';
if (dwTime[1] > 0) then
begin
if (Length(result) > 0) then
result:=result+' '+IntToStr(dwTime[1])+'d'
else
result:=result+' '+IntToStr(dwTime[1])+'d';
end;

if (Length(result) > 0) then
result:=result+Format(' %.2d:%.2d:%.2d', [dwTime[2], dwTime[3], dwTime[4]])
else
result:=result+Format('%.2d:%.2d:%.2d', [dwTime[2], dwTime[3], dwTime[4]]);

end;

0

LVL 26

Expert Comment

ID: 16964844
My bad, I was using seconds on the calculations...

Russell
0

Author Comment

ID: 16966601
hoi rllibby,

I have test our solutions. i see the
By great number workt it. (great !)
test 1 example result 2123333 min = 14w 3d 05:48:53
test 2 example result 810 min =   00:13:30 ??? must by 1d:05:30:00
test 3 example result 510 min =   00:08:30 ist OK ?
it wont work correcly with small numbers ?
0

LVL 28

Expert Comment

ID: 16966706

if you are inputting minutes, how are you getting non-zero seconds?

I adapted my code to seconds input and indeed now I am getting your desired results. so you don't inputmin, you input seconds.

810 seconds are 13 min and 30 seconds not 1 day 5 hours and 30 min

function inttotimestr(s:integer):string;// input is minutes
var w,d,h,m,se:word;
begin
w:=s div (5*8*60*60);// 5 days with 8 hours having 60 min
s:=s mod (5*8*60*60);
d:=s div (8*60*60);
s:=s mod (8*60*60);
h:=s div (60*60);
s:=s mod (60*60);
m:=s div 60;
se:=s mod 60;
result:=format('%d:%.2d:%.2d:%.2d:%.2d',[w,d,h,m,se]);
end;
0

LVL 28

Expert Comment

ID: 16966712
here is code with changed formatting to output as you requested:

function inttotimestr(s:integer):string;// input is seconds
var w,d,h,m,se:word;
begin
w:=s div (5*8*60*60);// 5 days with 8 hours having 60 min
s:=s mod (5*8*60*60);
d:=s div (8*60*60);
s:=s mod (8*60*60);
h:=s div (60*60);
s:=s mod (60*60);
m:=s div 60;
se:=s mod 60;
result:=format('%dw %dd %.2d:%.2d:%.2d',[w,d,h,m,se]);
end;
0

LVL 10

Accepted Solution

atul_parmar earned 500 total points
ID: 16966830
Just call MinutesBetween function.

:)
0

LVL 10

Expert Comment

ID: 16966842
Also see

MinuteOf
MinuteOfTheDay
MinuteOfTheHour
MinuteOfTheMonth
MinuteOfTheWeek
MinuteOfTheYear
MinutesBetween
MinuteSpan
0

LVL 10

Expert Comment

ID: 16967106
B ??????????????????????
0

LVL 28

Expert Comment

ID: 16967131
but of course. you didn't provide code on how to use it. beside that not answering the question :P I just can't figure out how to use those minute* functions to achieve what the asker wanted (convert minute or seconds, still not clear to a string representation with weeks, days, etc).
so B is more than enough :P

a little sarcastic this morning :D
i'm in a good mood, though I have a papre due in 30 minutes and it's ... far from ready. and instead of working on that, I am writing this. totally illogical.

oh well, back to my paper :)
0

LVL 10

Expert Comment

ID: 16967203
For Delphi programmer at least I can expect that he knows how to call a simple function. :)
0

LVL 10

Expert Comment

ID: 16967218
Btw, all the best Ciuly!! Infect, instead of all the best I must say Congratulates!!
0

LVL 28

Expert Comment

ID: 16967266
hehe, calling is not the issue, rather the usage. AFAIK, minutesbetween takes 2 TDateTime's as arguments and spit's out an integer if I am correct (I'm not starting uup the ide cause I've got a few stuff opena dn only 256 mb of ram :( )
now ... we have an integer as input... so the usage is a little tricky.

btw, I have woken up for quite some hours, but I can't figure out what are the congratulations for.
0

LVL 10

Expert Comment

ID: 16967293
Re:
i'm in a good mood, though I have a papre due in 30 minutes and it's ... far from ready. and instead of working on that, I am writing this. totally illogical.

oh well, back to my paper :)

For ppl I m confident on, I say Congrats rather than All the Best! (i.e. I dont wait for result)
0

LVL 28

Expert Comment

ID: 16967386
oh, that makes sense now :))
thanks
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question