# problem with monthly Reporting

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!

## Comments

• : 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:
[code]
var
Date1, Date2: TDateTime;
begin
Date1 := EncodeDate(2006, 5, 1);
Date2 := Date;
Label1.Caption := FloatToStr(Date2-Date1);
end;
[/code]
shows the number of days between 1-5-2006 and today.
• : : 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:
: [code]
: var
: Date1, Date2: TDateTime;
: begin
: Date1 := EncodeDate(2006, 5, 1);
: Date2 := Date;
: Label1.Caption := FloatToStr(Date2-Date1);
: end;
: [/code]
: 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

• : : : 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:
: : [code]
: : var
: : Date1, Date2: TDateTime;
: : begin
: : Date1 := EncodeDate(2006, 5, 1);
: : Date2 := Date;
: : Label1.Caption := FloatToStr(Date2-Date1);
: : end;
: : [/code]
: : 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:
[code]
Date2 := Date;
for i := 1 to 12 do
begin
Date1 := EncodeDate(2006, i, 1);
Memo1.Lines.Add(FloatToStr(Date2-Date1));
end;
[/code]
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:
[code]
Date1 := EncodeDate(StrToInt(edtYear.Text), StrToInt(edtMonth.Text), StrToInt(edtDay.Text));
[/code]
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()).
Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!