Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get date format from a ClientDataset

Posted on 2011-09-04
9
Medium Priority
?
670 Views
Last Modified: 2012-05-12
Hi all.
I'm writing a small app - I only write small apps :-) - to write an sql dump file from a ClientDataset. I'm now trying to convert dates. So, assunming in MySql I have to insert values in the following format

yyyy-mm-dd

I wish to know how to get the format date are stored within ClientDataset. Since this format depends on locxal settings I can have in date field a string like 'dd/mm/yyyy', or 'mm/dd/yyyy' and so on. I should be able to get the actual date format within ClientDataset in order to convert that date in the format 'yyyy-mm-dd' (I solved yet the problem of slashes and dashes using AnsiReplaceText function)

Thanks to all for any help.

Marco
0
Comment
Question by:Marco Gasi
[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
  • 4
9 Comments
 
LVL 13

Expert Comment

by:Ashok
ID: 36480574
Use getdateformat
It is a windows API.

http://winapi.freetechsecrets.com/win32/WIN32GetDateFormat.htm

HTH
Ashok

0
 
LVL 13

Expert Comment

by:Ashok
ID: 36480584
procedure TForm1.Button1Click(Sender: TObject);
var
  lSystemTime : TSystemTime;
  lBuffer : array[0..64] of Char;
  lErrorCode : Integer;
begin
  FillChar(lSystemTime, sizeof(TSYSTEMTIME), #0);
  lSystemTime.wDay := 25;
  lSystemTime.wMonth := 8;
  lSystemTime.wYear := 2004;

  if GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, @lSystemTime, nil,
    lBuffer, sizeof(lBuffer)) <> 0 then
    ShowMessage(string(lBuffer))
  else
    ShowMessage(SysErrorMessage(GetLastError));
end;
0
 
LVL 31

Author Comment

by:Marco Gasi
ID: 36480636
Thanks for your reply.

Let me explain better. My app doesn't know anything about ClientDataset it's going to migrate in mysql dump file. It get field type iterating through the dataset opened by user. If it encounter date field it has to know which formt that value use. Theorically, user could be swedish but it could try to convert a dataset filled with an US format. I can't assume that dataset format corresponds to system locale. So, if ClioentDataset doesn't hold any information about date field format, maybe I have to use some regular expression to understand wich format date field use...

I'm wrong?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Expert Comment

by:Ashok
ID: 36480694
If user could be swedish, is he/she using computer in USA?

If so, ClientDataset will not hold any format info by default within the same date field.
If you know how many different formats you will be supporting, you could add one extra field and have format stored as string.

HTH
Ashok
 
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 36480717
How is the CLientDataSet created?

mlmcc
0
 
LVL 31

Author Comment

by:Marco Gasi
ID: 36480796
I'm tryin to write a progam to allow to anyone to create a mysql dump file from any ClientDataset. It should be an utility for Delphi programmers who need to migrate some MyBase database to mysql, so I can't to know how a ClientDataset is created, nor I can create any extra field.

Perhaps I could let the user tells date format used by selecting it from a combobox... Or I could try to get string and trhen chenge its format using regular expression. The problem is not the creation opf the dump file: this is yet done. But when I tried to import with PhpMyAdmin, date format has not been recognized and all dates have been wrote as '0000-00-00' in the mysql database.

Any idea?
0
 
LVL 13

Expert Comment

by:Ashok
ID: 36480841
You could add Calculated field to ClientDataset at runtime.

Then use calculated field to determine which format to use to show date.

Ashok
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 0 total points
ID: 36480883
Sorry, but it was a trivial task: iterating throught the dataset, I can just use

value := QuotedStr(FormatDateTime('yyyy-mm-dd', StrToDate(Fields.Fields[x].AsString)));

where value is the string that will be written in the value clause of sql statement INSERT

I'm going to ask to close this question. I'm very sorry for having wasted your time: hope youìll excuse me.

Thanks for having tried to help me.
0
 
LVL 31

Author Closing Comment

by:Marco Gasi
ID: 36508820
I solved my problem by myself because I understood that it was trivial.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
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

609 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