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

Hoi,

I have make somthing, but it wont work correcly.
Please help my

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;


kuken1Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
atul_parmarConnect With a Mentor Commented:
Just call MinutesBetween function.

:)
0
 
2266180Commented:
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
 
Russell LibbySoftware Engineer, Advisory Commented:
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;

  // Add remaining hours:minutes:seconds
  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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Russell LibbySoftware Engineer, Advisory Commented:
My bad, I was using seconds on the calculations...

Russell
0
 
kuken1Author Commented:
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
 
2266180Commented:
I am still confused about this:

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.

regarding your "small numbers"
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
 
2266180Commented:
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
 
atul_parmarCommented:
Also see

MinuteOf
MinuteOfTheDay
MinuteOfTheHour
MinuteOfTheMonth
MinuteOfTheWeek
MinuteOfTheYear
MinutesBetween
MinuteSpan
0
 
atul_parmarCommented:
B ??????????????????????
0
 
2266180Commented:
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
 
atul_parmarCommented:
For Delphi programmer at least I can expect that he knows how to call a simple function. :)
0
 
atul_parmarCommented:
Btw, all the best Ciuly!! Infect, instead of all the best I must say Congratulates!!
0
 
2266180Commented:
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
 
atul_parmarCommented:
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
 
2266180Commented:
oh, that makes sense now :))
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.