# Board index » delphi » Converting hours to weeks and days ?

## Converting hours to weeks and days ?

Does anybody have a function or an algorithm which will convert a given
number of hours to the corresponding number of weeks and days ?

## Re:Converting hours to weeks and days ?

##### Quote
Lars Lindg?rd wrote in message <36310610.66A40...@online.no>...
>Does anybody have a function or an algorithm which will convert a given
>number of hours to the corresponding number of weeks and days ?

Have you tried the standard Delphi function DecodeTime, DecodeDate?

Marko
---------------

## Re:Converting hours to weeks and days ?

I might be missing something subtle in your question, but wouldn't;
days := hours div 24;
weeks := days div 7;
do the trick?

--
Garry Knight
Computer programmer, psychotherapist, writer
ga...@garryknight.freeserve.co.uk

##### Quote
Lars Lindg?rd wrote in message <36310610.66A40...@online.no>...
>Does anybody have a function or an algorithm which will convert a given
>number of hours to the corresponding number of weeks and days ?

## Re:Converting hours to weeks and days ?

In article <36310610.66A40...@online.no>, "Lars Lindg?rd" <lindg...@online.no>
writes:

##### Quote
>Does anybody have a function or an algorithm which will convert a given
>number of hours to the corresponding number of weeks and days ?

If you are adjusting the date by the number of hours then remember that the
Delphi date variable is a double which holds the day value as the whole number
part, and the part of a day as the fractional part.

So a time some hours hence is :-

Date_Time_Ahead := Now + (ElapsedHours / 24);

. . . and use the normal methods of turning a TDateTime into a string
DateTimeToStr() or of extracting the Hour, Day, Month, and Year (ie
DecodeDate()).

If you are converting hours directly to weeks, days and hours

Weeks := ElapsedHours div 168;
Days := (ElapsedHours div 24) mod 7;
or Days := (ElapsedHours mod 168) div 24;
Hours := ElapsedHours mod 24;

Alan Lloyd
alangll...@aol.com

## Re:Converting hours to weeks and days ?

This surely would do the trick as hours in weeks and days are integers. However I
needed a routine which would be able to convert the hours in a "working" week (in
Norway that is 37.5 hours) to weeks and days. (My fault. I didn't explain my
problem very well.) So I would have to be able to use real-numbers.
Anyway I figured out a way to do it myself.  Thanks for all your help anyway.
##### Quote
AlanGLLoyd wrote:
> In article <36310610.66A40...@online.no>, "Lars Lindg?rd" <lindg...@online.no>
> writes:

> >Does anybody have a function or an algorithm which will convert a given
> >number of hours to the corresponding number of weeks and days ?

> If you are adjusting the date by the number of hours then remember that the
> Delphi date variable is a double which holds the day value as the whole number
> part, and the part of a day as the fractional part.

> So a time some hours hence is :-

> Date_Time_Ahead := Now + (ElapsedHours / 24);

>  . . . and use the normal methods of turning a TDateTime into a string
> DateTimeToStr() or of extracting the Hour, Day, Month, and Year (ie
> DecodeDate()).

> If you are converting hours directly to weeks, days and hours

> Weeks := ElapsedHours div 168;
> Days := (ElapsedHours div 24) mod 7;
> or Days := (ElapsedHours mod 168) div 24;
> Hours := ElapsedHours mod 24;

> Alan Lloyd
> alangll...@aol.com