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
15
265 Views
Last Modified: 2010-04-05
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;


0
Comment
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
  • Learn & ask questions
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 28

Expert Comment

by:2266180
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

by:Russell Libby
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;

  // 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
 
LVL 26

Expert Comment

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

Russell
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kuken1
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

by:2266180
ID: 16966706
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
 
LVL 28

Expert Comment

by:2266180
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

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

:)
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16966842
Also see

MinuteOf
MinuteOfTheDay
MinuteOfTheHour
MinuteOfTheMonth
MinuteOfTheWeek
MinuteOfTheYear
MinutesBetween
MinuteSpan
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16967106
B ??????????????????????
0
 
LVL 28

Expert Comment

by:2266180
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

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

Expert Comment

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

Expert Comment

by:2266180
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

by:atul_parmar
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

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
URL for downloading Google Chrome for Win XP 2 282
Find and Replace Stream with 0s 8 87
Firemonkey DbLookupComboBox equivalent ? 2 78
RESTRequest Parameter 4 81
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question