?
Solved

Convert date

Posted on 2014-03-03
6
Medium Priority
?
423 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 38

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 38

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 38

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 38

Accepted Solution

by:
Geert Gruwez earned 1000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 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