1 (edited by mathmathou 2015-03-14 12:37:52)

Topic: Difference between 2 dates WITHOUT week-ends

Hello Dmitry,


Again, I'm asking for help smile


After successfully (thanks to you) calculating a total number of days, hours, minutes between 2 dates, I am trying to calculate to total number of working days between the same dates.


In other word, I am trying to count the DaysBewteen minus Saturdays and Sundays.


I used the DayOf Week (week starts with a Sunday) because it seems that the DayOfTheWeek (week starts with a Monday) is not yet implemented (which does not matter at all in fact).


I suppose what must be done is calculate the total number of days between the dates, and substract all the [1] and [7] days (Sundays and Saturdays) with some kind of loop... but how ?


Do you have a idee for me ? Or anyone else maybe ?


In the included project, days of beginning and ending dates are identified, and DaysBetween are also calculated but I don't have a clue on how to substract Saturdays and Sundays sad


MVDB version is 1.50

Post's attachments

Attachment icon WE.zip 333.62 kb, 566 downloads since 2015-03-14 

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Difference between 2 dates WITHOUT week-ends

I made function for you, which calculate total number of working days between two dates

function CalculateWorkDays (startdate, enddate: TDateTime): integer;
var
    i: integer;
    iDays: integer;
    start, stop: integer;
begin
    iDays := 0;
    start := Trunc(startdate);
    stop := Trunc(enddate);

    for i := start to stop do
        if (DayOfWeek(i)<>7) and (DayOfWeek(i)<>1) then Inc(iDays);

    Result := iDays;
end;
Dmitry.

Re: Difference between 2 dates WITHOUT week-ends

Dmitry you're the best !


I was trying something like :

  • count days

  • find what the first day is

  • divide total number of days by 7

  • chain the if conditions with divisions and modulos to find how many saturdays and sundays

This looks like pure magic to me and in the same time it is so logical now that it is written !


Thanks again

Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Difference between 2 dates WITHOUT week-ends

Hello Dmitri and Mathias

Your script about Difference between 2 dates WITHOUT week-ends is very interesting.

Mais When I want launch Matthias's project WE, I got an error :

'The selected project was created by a newer version of this application and cannot be opened.

I'm using last version of MVD (1.50) loaded from official site ( Version: 1.49 (16 February 2015)

When I opened his WE.vdb, I read   [info] version=3

With my version 1.49, I read [info]  version=2

What's the matter with my version ?

Thanks

JB

Re: Difference between 2 dates WITHOUT week-ends

[info]  version
This version of compatibility


I made some changes that are not compatible.
If you made a project in version 1.50, you can't open this project in version 1.49


But if you made a project in version 1.49, you can open this project in version 1.50

Dmitry.

Re: Difference between 2 dates WITHOUT week-ends

Thanks Dmitry

Now I understand why

If there is no secret to reveal it, what's the different meanings for
Ver=2
Ver=3

and I see now  Ver=4

verTables=1
verForms=1
version=2

Excuse my curiosity

Cordialy

JB

Re: Difference between 2 dates WITHOUT week-ends

File structure of the database ("tables.ini") is now in UTF-8
also the file "Script.ini"

Dmitry.

8 (edited by mathmathou 2015-03-16 22:33:33)

Re: Difference between 2 dates WITHOUT week-ends

Hello Jean (and Dmitry),


Here is the final WE app for testing. There is no other use for this tool than implementing what Dmitry gave me for counting working days, and also a demonstration on how to dynamically change the title bar of the window based on a calendar click.

As stated by Dmitry, this is developped under the last version of V1.50

Have a good day all

Cheers


Mathias

PS : and again many thanks to Dmitry

Post's attachments

Attachment icon WE2.zip 335.22 kb, 581 downloads since 2015-03-16 

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor