Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
problem with monthly Reporting Posted by smsaid on 28 May 2006 at 12:35 PM
Hi !
I have this problem, I want develop a report passed on monthly but I have a problem how i can determine the ongoing month for eg. the date is 28-05-2006 to show in my report from the begining of the month eg. 01-05-2006 to the days date programatically. Please help!
Report
Re: problem with monthly Reporting Posted by zibadian on 28 May 2006 at 1:04 PM
: Hi !
: I have this problem, I want develop a report passed on monthly but I have a problem how i can determine the ongoing month for eg. the date is 28-05-2006 to show in my report from the begining of the month eg. 01-05-2006 to the days date programatically. Please help!
:
In Delphi dates (and times) are stored as numbers from a set 0-date. To get the difference between two dates, you can just subtract them. This will give you the number of days between them in the integer range, while the fractions represent the hours/minutes/seconds between them. Thus:
var
  Date1, Date2: TDateTime;
begin
  Date1 := EncodeDate(2006, 5, 1);
  Date2 := Date;
  Label1.Caption := FloatToStr(Date2-Date1);
end;

shows the number of days between 1-5-2006 and today.
Report
Re: problem with monthly Reporting Posted by smsaid on 28 May 2006 at 1:13 PM
: : Hi !
: : I have this problem, I want develop a report passed on monthly but I have a problem how i can determine the ongoing month for eg. the date is 28-05-2006 to show in my report from the begining of the month eg. 01-05-2006 to the days date programatically. Please help!
: :
: In Delphi dates (and times) are stored as numbers from a set 0-date. To get the difference between two dates, you can just subtract them. This will give you the number of days between them in the integer range, while the fractions represent the hours/minutes/seconds between them. Thus:
:
: var
:   Date1, Date2: TDateTime;
: begin
:   Date1 := EncodeDate(2006, 5, 1);
:   Date2 := Date;
:   Label1.Caption := FloatToStr(Date2-Date1);
: end;
: 

: shows the number of days between 1-5-2006 and today.
:

Thanks ze
But as I see in the code shows only a one specific month proberly MAY month, but my problem is to show the ongoing month through out the year
Date1 := EncodeDate(2006, 5, 1) this will show in the begining of ONLY one month.
Thanks

Report
Re: problem with monthly Reporting Posted by zibadian on 28 May 2006 at 1:36 PM
: : : Hi !
: : : I have this problem, I want develop a report passed on monthly but I have a problem how i can determine the ongoing month for eg. the date is 28-05-2006 to show in my report from the begining of the month eg. 01-05-2006 to the days date programatically. Please help!
: : :
: : In Delphi dates (and times) are stored as numbers from a set 0-date. To get the difference between two dates, you can just subtract them. This will give you the number of days between them in the integer range, while the fractions represent the hours/minutes/seconds between them. Thus:
: :
: : var
: :   Date1, Date2: TDateTime;
: : begin
: :   Date1 := EncodeDate(2006, 5, 1);
: :   Date2 := Date;
: :   Label1.Caption := FloatToStr(Date2-Date1);
: : end;
: : 

: : shows the number of days between 1-5-2006 and today.
: :
:
: Thanks ze
: But as I see in the code shows only a one specific month proberly MAY month, but my problem is to show the ongoing month through out the year
: Date1 := EncodeDate(2006, 5, 1) this will show in the begining of ONLY one month.
: Thanks
:
:
Obviously the parameters to the EncodeDate() can be variables to be able to select different months. Here is another example:
  Date2 := Date;
  for i := 1 to 12 do
  begin
    Date1 := EncodeDate(2006, i, 1);
    Memo1.Lines.Add(FloatToStr(Date2-Date1));
  end;

This will show the difference for each first day in the months of this year. Remember also that the year and day can also be variables, and can be entered by the user using the appropriate controls. Example based on edits:
  Date1 := EncodeDate(StrToInt(edtYear.Text), StrToInt(edtMonth.Text), StrToInt(edtDay.Text));

But alas this code might not work if the user enters non-numbers as year, month and day. So you either need to validate them before hand or use a try-except block to show your own custom error messages.
If you want to have the current month then you can use DecodeDate() to split a date into the three parts (see help on DecodeDate()).



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.