Solved

Convert date

Posted on 2014-03-03
6
411 Views
Last Modified: 2014-03-03
Hi.

I have excel document where the name of the sheets is the date the sheet was created. But some of the sheets have a date format like this: dd/mm/yyyy and I want it like this: yyyy/mm/dd. The name of the sheets in a Listbox is added by using ADOConnection.GetTableNames(ListBox1.Items,false);

How can I convert the dateformat to the right one?
0
Comment
Question by:QC20N
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39900417
in delphi simply use FormatDateTime
FormatDateTime( 'yyyy/mm/dd', DateTimeValue)

can you actually use slashes in the file name, if not :
> FormatDateTime('yyyymmdd', DateTimeValue)

excel ???
0
 

Author Comment

by:QC20N
ID: 39900430
Yes, but how? :)

If you see in line 15 I add TableName to the listbox.

procedure TFrmMain.BtnADOConnectXLSClick(Sender: TObject);
var strConn :  widestring;
begin
  strConn := 'Provider=Microsoft.ACE.OLEDB.12.0;' +
             'Data Source=' + 'C:\path\Project Pro_SE.xlsx' + ';' +
             'Extended Properties="Excel 12.0 xml;HDR=YES";';
  AdoConnection1.Connected:=False;
  AdoConnection1.ConnectionString:=strConn;
  ADOConnection1.CursorLocation := clUseServer;
  ADOConnection1.LoginPrompt := false;
  ADOConnection1.Mode := cmShareDenyNone;
  ADOConnection1.Provider := 'Microsoft.ACE.OLEDB.15.0';
  try
    ADOConnection1.Open;
    ADOConnection1.GetTableNames(listbox1.Items,false);
  except
    ShowMessage('Unable to connect to Excel, make sure the workbook exist!');
    raise;
  end;
  AdoQuery1.CursorLocation:=clUseServer;
end;

Open in new window

0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39900443
how did the tablenames get in there ?

if you don't change them at that level  you'll need:
A > a translation from the orginal format to your new display format
B > that filename won't exist anymore, so you can't do anything with it in the next step

change the original filename formats by setting up a rule when entering the file names.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39900451
do you have some samples of correct and wrong filenames ?

without those samples,  it's guessing at what the interpretation converter should do
0
 

Author Comment

by:QC20N
ID: 39900463
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_28363030.html

Just below the accepted solution in the link there is file. If that is was you are asking. :)
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 250 total points
ID: 39900667
well that's basically swap-a-little
if the first '-' is at position 5 then it's ok, otherwise swap

besides your format is not with slashes but with minusses !!!

TempList := TStringList.Create;
try
  ADOConnection1.GetTableNames(TempList,false);
  ConvertDateList(TempList);
  listbox1.Items.Assign(TempList);
finally 
  TempList.Free;
end;

Open in new window


procedure TFormXXX.ConvertDateList(List: TStrings);
var I: Integer;
  Temp: string;
begin
  for I := 0 to List.Count-1 do
  begin
    Temp := List[I];
    if Pos('-', Temp) <> 5 then 
    begin
      Temp := Copy(Temp, 7, 4) + '-' + Copy(Temp, 4, 2) + '-' + Copy(Temp, 1, 2);
      List[I] := Temp;
    end;
  end;
end;

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question