Reverse date

Peter Kiers
Peter Kiers used Ask the Experts™
on
Dear Experts,

I have a Button, a ListView and a XMLDocument-component on my form.
I have put the Button1Click procedure in the code-section. When I press
on the button it uses the XMLDocument-component to parse the xml-file
that is specified in the procedure. It searches for the nodes that begins with 'BG'  
and displays from every node that begins with BG the values from Val, Dt and TM
into the Listview columns Value, Date and Time.

AND IT WORKS SUPER.

Only the date in the xml file is displayed like this: 2010-06-09
So I get this in the column date too. Is there a way to reverse
the date like this: 09-06-2010.

If you don't know what I mean. I have allready asked this question but then
I had a ClientDataset instead of a Listview.

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26280595.html

Is that possible? I hope someone knows the answer and is willing to help me.

Greetings,
Peter Kiers
procedure TForm1.Button1Click(Sender: TObject);
var
  LoopNodes : IDOMNodeList;
  i: Integer;
begin
  XMLDocument1.FileName := '.\MyDB.xml';
  XMLDocument1.Active := True;
  try
    LoopNodes:= XMLDocument1.DOMDocument.getElementsByTagName( 'BG' );

    ListView1.Items.BeginUpdate;
    try
      for i:= 0 to LoopNodes.length -1 do
        with ListView1.Items.add do begin
          Caption:= LoopNodes[i].attributes.getNamedItem('Dt').nodeValue;
          SubItems.Add( LoopNodes[i].attributes.getNamedItem('Tm').nodeValue );
          SubItems.Add( LoopNodes[i].attributes.getNamedItem('Val').nodeValue );
        end;
    finally
      ListView1.Items.EndUpdate;
    end;

  finally
    XMLDocument1.Active := False;
  end;
end;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Geert GOracle dba
Top Expert 2009

Commented:
you allready asked this in a previous question
same mo
s := LoopNodes[i].attributes.getNamedItem('Dt').nodeValue;
Caption := DateToStr(EncodeDate(StrToInt(Copy(s,1,4)),StrToInt(Copy(s,6,2)),StrToInt(Copy(s,9,2))));
Top Expert 2010
Commented:
with 4th column "day":

procedure TForm1.Button1Click(Sender: TObject);
const
  FormatFrom: TFormatSettings = (DateSeparator: '-'; ShortDateFormat: 'yyyy-mm-dd');
  FormatTo: TFormatSettings = (DateSeparator: '-'; ShortDateFormat: 'dd-mm-yyyy');
  Days : array[1..7] of string
    = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var
  LoopNodes : IDOMNodeList;
  i: Integer;
  DateTime: TDateTime;
  Day: string;
begin
  XMLDocument1.FileName := '.\XMLDocument1.xml';
  XMLDocument1.Active := True;
  try
    LoopNodes:= XMLDocument1.DOMDocument.getElementsByTagName( 'BG' );

    ListView1.Items.BeginUpdate;
    try
      for i:= 0 to LoopNodes.length -1 do
        with ListView1.Items.add do
        begin
          Caption:= LoopNodes[i].attributes.getNamedItem('Val').nodeValue;
          if TryStrToDate(LoopNodes[i].attributes.getNamedItem('Dt').nodeValue, DateTime, FormatFrom) then
          begin
            SubItems.Add( DateToStr( DateTime, FormatTo ) );
            Day:= Days[ DayOfWeek(DateTime) ];
          end
          else
          begin
            SubItems.Add( LoopNodes[i].attributes.getNamedItem('Dt').nodeValue );
            Day:= 'can''t convert date';
          end;

          SubItems.Add( LoopNodes[i].attributes.getNamedItem('Tm').nodeValue );
          SubItems.Add( Day );
        end;
    finally
      ListView1.Items.EndUpdate;
    end;

  finally
    XMLDocument1.Active := False;
  end;
end;
Peter KiersOperator

Author

Commented:
It works great.

Thanks.

Peter

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial