FORMATDATETIME

Hi,

I'm trying to place the leading 0's in my date. I'm trying to use the function, FORMATDATETIME(format, DateTime). However, when I try to use any format the allows/displays leading zeros, it simply doesn't? Below are a couple examples of what I'm doing.

dtp_StartDate & dtp_StopDate are "Date Edit" controls.

StartDate := FORMATDATETIME('MM/DD/YYYY', dtp_StartDate.Date);
StopDate := FORMATDATETIME('MM/DD/YYYY', dtp_StopDate.Date);

I believe there are some type issues here and I need to find a work around. Is there anyone out there that can help me, please.

Randel

Comments

  • edited 11:42AM
    Okay,

    I have to apologize; I've made a small mistake. The actual function and it's format strings do appear to work. Below is some more code to test this a bit farther.

    begin
    Day := [FORMATDATETIME('DD/', dtp_StartDate.Date)];
    Month := [FORMATDATETIME('MM/', dtp_StartDate.Date)];
    Year := [FORMATDATETIME('YYYY', dtp_StartDate.Date)];

    Edit1.Text := Month;
    Edit2.Text := Day;
    Edit3.Text := Year;

    StartDate := Edit1.Text + Edit2.Text + Edit3.Text;

    Edit4.Text := StartDate;
    end

    Displayed Values:
    Edit1: "06/"
    Edit2: "01/"
    Edit3: "2004"
    Edit4: "0.0029940119760479"

    Needed/Wanted Value:
    Edit4: "06/01/2004"

    If the Date Time control is set to "June 1, 2004 (6/1/ 2004)", the value displayed in Edit4 is: 0.0029940119760479. This is gotten by dividing the text of Edit1 ("06/") by the text of Edit2 ("01/") and then dividing that by the text of Edit3 ("2004").

    However, I still have no way to be able to display or hold the date value in the format "MM/DD/YYYY".

    Can anyone help me with this?

    Thanks,

    Randel
  • gordkgordk St.Catherines On. Canada.
    edited 11:42AM
    hi works ok for me
    look at your format function
    Day := [FORMATDATETIME('DD/', dtp_StartDate.Date)];
    should be
    Day := [FORMATDATETIME('DD/', [dtp_StartDate."Date"])];
    remember when you want to retreive the value of a var or datafield to wrapit with
    [].
    Also is very bad practice to have date fields named date. date is a delphi function that returns current date.
    regards ;)
  • edited 11:42AM
    hi gork,

    I think we have a misunderstanding. Let me explain what I think you are talking about, so that I don't compound it.

    I believe you are saying that "dtp_StartDate.Date" or simply "Date" is a variable or a data field from some kind of dataset. If that is what you are thinking, it's not correct. As stated in my first post, the "dtp_StartDate" is one of FastReport's controls; it's the "Date Edit" control. The "Date" is what I've interpretted as it's "Date" property. I am taken this from my experience with Borland's C++ Builder. In Builder, a TDateTimePicker object has , the date value can either be set or retrieved via it's "Date" property.

    With that being said, I'm sorry but your solution doesn't work for me. So I'm not sure that I'm doing wrong to get yours to work.

    Randel
  • gordkgordk St.Catherines On. Canada.
    edited 11:42AM
    Hi Randel
    with the frdateedit control try using dateedit1.text
    the date edit picks up on the system default, IIRC and you can modify how it displays the year.
    so if your dateedit control displays a date looking like mm/dd/yyyy for example 01/12/2004
    you can pass that to a variable without needing any formatting
    ie in the onclick event of a button on the frdialog form
    startdate := dateedit1.text;
    and then using [startdate] in a memo. You don't need to set display format of the memo.
    If the dateedit control displays the date in some other format
    then you just need to chain the necessary functions to get what you desire.

    stardate :=[FORMATDATETIME('mask', [strtodate(dateedit1.text)])];
    thats how i do it in delphi.
    regards ;)

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.