How can I create a formula to compare my schedule time?

Posted on 2009-05-15
Last Modified: 2012-05-07
I would like to have 3 edits

first edit
I would inform the monthly time
example: 10 hours

Second edit
I would inform how many minutes per day I will study
example: 30 minutes

the system will inform how many hours I am falling behind in my studies,
all this will be done within the current month

I am a little bit how to achieve this formula,
thanks any help
Question by:hidrau
  • 5
  • 3
  • 3
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
write a big note with the time you want to study that month

put a stopwatch in your pocket
when you start studying, hit start
and when you stop .... yesss ... hit stop !

some stopwatches you can even set to count down ...

you could create this simply with a program too
a countdown timer with a start/stop button.
you wouldn't have to calculate at all !!!

Author Comment

Comment Utility
You understood partly of my problem, maybe I haven't explained it better.

Let me give you some details.

I have a program that I developed and I use to study english.
I would like to create a study plan. Then I will inform the program how many hours per month
I will dedicate with it.

The program will advice me how many hours or minutes per day I must study to achieve my schedule.
according to passing days, my system will compute how many minutes I studied and inform me if I am falling behind or if I am up to date with my studies.

So, imagine something like this:

I've chosen 10 hours per month to study
My studied per day must be 29 minutes

I got make this so far, I developed a function to give my monthly schedule

Now I need another part, I need to get all time I have studied within my month and
compare with my schedule and inform if I am falling behind or I am up to dated.

Take a loot at my code, can you help me improve my code?

My dfm

object Form1: TForm1

  Left = 370

  Top = 121

  Width = 535

  Height = 215

  Caption = 'Form1'

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'MS Sans Serif'

  Font.Style = []

  OldCreateOrder = False

  PixelsPerInch = 96

  TextHeight = 13

  object Label1: TLabel

    Left = 32

    Top = 16

    Width = 78

    Height = 13

    Caption = 'Hours per month'


  object Label2: TLabel

    Left = 162

    Top = 16

    Width = 94

    Height = 13

    Caption = 'Hours studied so far'


  object Edit1: TEdit

    Left = 32

    Top = 32

    Width = 121

    Height = 21

    TabOrder = 0

    Text = '10'


  object Edit2: TEdit

    Left = 161

    Top = 31

    Width = 121

    Height = 21

    TabOrder = 1

    Text = 'Edit2'


  object LB_ESQUEMA: TPanel

    Left = 32

    Top = 88

    Width = 457

    Height = 89

    Caption = 'LB_ESQUEMA'

    TabOrder = 2


  object Button1: TButton

    Left = 312

    Top = 27

    Width = 75

    Height = 25

    Caption = 'schedule'

    TabOrder = 3

    OnClick = Button1Click



My pas

unit Unit1;



  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, DateUtils, StdCtrls, ExtCtrls;


  TForm1 = class(TForm)

    Edit1: TEdit;

    Edit2: TEdit;

    LB_ESQUEMA: TPanel;

    Button1: TButton;

    Label1: TLabel;

    Label2: TLabel;

    procedure Button1Click(Sender: TObject);


    { Private declarations }


    { Public declarations }



  Form1: TForm1;


{$R *.dfm}

procedure hour_to_learn(Ahours, AMonth, AYear:integer) ;


 i, no_w, no :integer;

 Adate       :tdatetime;

 V1, v2, v3 : String;


  V1    := ' Hour per month, ';

  V2    := ' days = ';

  V3    := ' minutes per day ';

  no    :=0;

  adate :=EncodeDate(ayear, amonth,1);

  no_w  :=DaysInMonth(adate);

  for i:=1 to no_w do


    if (DayOfWeek(adate) >= 2) AND (DayOfWeek(adate) <= 6) then no:=no+1;



//  LB_ESQUEMA.Caption := inttostr(ahours) + Fmenu.PegaVariavel('FTEMPOAULA_01') + inttostr(no)+ Fmenu.PegaVariavel('FTEMPOAULA_02') + inttostr(round(ahours*60/no))+Fmenu.PegaVariavel('FTEMPOAULA_03')+ #13#10+

//             inttostr(ahours)+Fmenu.PegaVariavel('FTEMPOAULA_01')+ inttostr(no_w)+Fmenu.PegaVariavel('FTEMPOAULA_02')+inttostr(round(ahours*60/no_w))+Fmenu.PegaVariavel('FTEMPOAULA_03');

  Form1.LB_ESQUEMA.Caption := inttostr(ahours) + V1 + inttostr(no)   + V2 + inttostr(round(ahours*60/no))  + V3 + #13#10+

                        inttostr(ahours) + V1 + inttostr(no_w) + V2 + inttostr(round(ahours*60/no_w))+ V3;


procedure TForm1.Button1Click(Sender: TObject);


  Hr : Integer;


  Hr := StrToInt(Edit1.Text);

  hour_to_learn(Hr,MonthOf(Date), YearOf(Date));



Open in new window

LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
studying a language like this will not get you anywhere.
Just go to the library, select 2 or 5 books from each cabinet and read them.
You will be excellent at English after 100 books, providing the books cover a wide range of subjects.
You may need a encylcopedia for explanations ...

I studied French and English like this.
I started on Japanese, but the barrier is way bigger.
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
for the formula
query pseudo :

total - sum (end_time - start_time) = still_to_go
LVL 13

Expert Comment

Comment Utility
lol @ Geert.

Yaknow, part of this type of problem-solving is what I enjoy about programming, and this isn't even that complicated. Can you not by yourself come up with a formula or algorithm and then ask us to help you put the formula into code?
Part of the problem is you haven't given us quite enough information, for example:
"the system will inform how many hours I am falling behind in my studies,
all this will be done within the current month"
So let's say today is the 15th of May. Can you give me an example of what you would put in the boxes and what the answers will be? Or does it calculate from the BEGINNING of the month? Your question is not clear on this.

Geert has given you an algorithm that could work for you.
If that's not right for you then how about this one:
total - (DayOfMonth(Today) * MinutesStudiedPerDay) = still_to_go
for example, if today is the 15th, it will look like this:
10 hours - (15 * 29) = 165 minutes. behind

I'm also glad to see you are using DateUtils which can come in handy for some things.

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

LVL 36

Accepted Solution

Geert Gruwez earned 500 total points
Comment Utility
you have been reposting this question in different formats
and your gui is very complex, keep it simple, or you'll never get there.

use a db with 4 fields, index (prim key), startdate, enddate, course
you don't need anything more for this !

the algorithm works, it's the rest your messing up.

i wrote several programs for time registration on company production floors. (big companies and small companies)
it always comes down to the same thing:
calculate the delta for each record from start to finish
you may need to split the record to include breaks/toilet visits/line halts/planned halts ... whatever
then just sum it up

like this

id start  end    code

1  12:00  14:00  productA

2  14:00  17:00  productB

3  17:00  18:00  productC

4  18:00  20:00  productA

how long did they work on A, when

the line halted from 13:12 to 13:45

and they take breaks at 15:00 to 15:15 and 18:00 to 18:15


split according to breaks and calc deltas:

id  start  end    code     delta  add

1   12:00  14:00  productA 120    1  

2   14:00  15:00  productB  60    1 

2a  15:00  15:15  productB  15    0

2b  15:15  17:00  productB 105    1

3   17:00  18:00  productC  60    1

4   18:00  18:15  productA  15    0

4a  18:15  20:00  productA 105    1

now split with line halts

id  start  end    code      delta  add

1   12:00  13:12  productA  72    1  

1b  13:12  13:45  productA  33    0  

1c  13:45  14:00  productA  15    1

2   14:00  15:00  productB  60    1 

2a  15:00  15:15  productB  15    0

2b  15:15  17:00  productB 105    1

3   17:00  18:00  productC  60    1

4   18:00  18:15  productA  15    0

4a  18:15  20:00  productA 105    1

the select: 

select sum(delta) from calctimes

where add = '1'

  and code = 'productA'

result: 72 + 15 + 105 = 192

if they can work on product hour for 10 hours to complete: 600 - 192 = 408

then you can even calc the percentage they have finished: 192/600*100 = 32%

after some time you would have statistics on how much they can work on a productA, (let's say 3 hours a day)

then you can calc if they are ahead or behind for the deadline

totaltodo - currentdone = stilltogo

stilltogo / 3hoursperday = days to go

today + days to go = day finished

compare day finished to deadline to know if ahead or not

anything you don't understand about this simple algorithm ?

Open in new window

LVL 13

Expert Comment

Comment Utility
Can you explain the add column? It is obviously a flag of some kind, but I'm not sure for what.
LVL 13

Expert Comment

Comment Utility
Silly me, with another glance I could see it's a flag on whether or not to add that record into the calculation - kind of like a "relevant?" flag.
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
well the add flag is really a simple method of indeed indicating if something was really done.
normally this is done by entering a code from a reasoncode table.
this reasoncodetable would allow to extend to more functionality with 1 piece of code
like for every delta you could designate:
- the type of time: break, hours worked, electric failure, machine failure, product change, etc...
- flags: billable, production hours, down hours, maintenance hours
- percentage billable
- cost center

if you chop up all time a employee worked and categorize every piece of time into this system
you get the group summary with a simple select sum group by on a daily/weekly/monthly/yearly basis
the better you can divide the time into those delta, the more accurate
like with the cost center you could determine if money is comming in or going out.
and then what you earned or what you lost

Author Comment

Comment Utility

well, I am returning to this project today.

Just answering your question:

>>"the system will inform how many hours I am falling behind in my studies,
>>all this will be done within the current month"


I have a table in access that keep the amount of minutes / hours that I have studied. This column keep the information in hh:mm

When I start my month, I inform the system what it will be the amount of hour I will dedicate on my studies. For exemplo:

My goal for this month is 15 hours.
With this information, I can split the hours in days, then I can see how many hours / minutes I need to study to achieve my goal. As you can see in the function that I have posted

With my table, I will be able to sum how many minutes / hours I have studied so far and how many minutes / hours I need to achieve my goal. If I am falling behind with the chosen schedule, the system must inform me the amount of minutes or hours I am late.

Did you get it?

Author Closing Comment

Comment Utility

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now