?
Solved

Date String to TDate

Posted on 2008-11-03
8
Medium Priority
?
751 Views
Last Modified: 2010-04-21
I need to convert a date string to a TDate

How to convert  'November 3, 2008'   to 11/03/08

thanks
0
Comment
Question by:geocoins-software
[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
  • 2
8 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 22867626
You want to avoid this at all cost, so if you do this, you probably went somewhere wrong earlier.

Why do you want to do this?
0
 

Author Comment

by:geocoins-software
ID: 22867676
This is a string returned from parsing an html file.

<td valign="top">October 28, 2008      </td></tr>

thanks
0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 1000 total points
ID: 22867702
here is the code using the USER_LOCALE
function ConvertDate(aDateString: string): TDateTime;
var aMonth, aYear, aDay: Word;
  I: Integer;
  Temp: string;
  fmt: TFormatSettings;
begin
  GetLocaleFormatSettings(LOCALE_USER_DEFAULT, fmt);
  aMonth := 1;
  Temp := Copy(aDateString, 1, Pos(' ', aDateString)-1);
  for I := 2 to 12 do
    if SameText(Temp, fmt.LongMonthNames[I]) then
    begin
      aMonth := I;
      Break;
    end;
  Temp := Copy(aDateString, Pos(' ', aDateString)+1, 2);
  if Temp[2] = ',' then
    Delete(Temp, 2, 1);
  aDay := StrToInt(Temp);
  Temp := RightStr(Trim(aDateString), 4);
  aYear := StrToInt(Temp);
  Result := EncodeDate(aYear, aMonth, aDay);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(FormatDateTime('DD/MM/YYYY', ConvertDate('November 3, 2008')));
end;

Open in new window

0
Technology Partners: 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 38

Expert Comment

by:Geert Gruwez
ID: 22867714
ow, the FormatDateTime should be

ShowMessage(FormatDateTime('MM/DD/YYYY', ConvertDate('November 3, 2008')));
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 22867718
oops again and the year to YY

ShowMessage(FormatDateTime('MM/DD/YY', ConvertDate('November 3, 2008')));
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 22867724
is the website always returning the date in the same language, is this the same language is the machine your app runs on (always)?
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 22867726
don't forget in the implementation to add the

uses StrUtils
0
 

Author Closing Comment

by:geocoins-software
ID: 31512710
THANK YOU!
0

Featured Post

Technology Partners: 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

800 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