Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

problem with monthly Reporting

smsaidsmsaid Posts: 11Member
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

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • smsaidsmsaid Posts: 11Member
    : : 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

  • zibadianzibadian Posts: 6,349Member
    : : : 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.