?
Solved

Format and unformat TDateTime

Posted on 2006-11-20
10
Medium Priority
?
325 Views
Last Modified: 2010-04-04
I have a function:



function DateToXMLStr(aDateTime: TDateTime): string;
var
 d : Char;
begin
  d:= DateSeparator;
  DateSeparator:= XML_DATE_SEPARATOR;

  if aDateTime = 0 then
  begin
    Result:= ''
  end else
  begin
    Result := FormatDateTime(XML_DATE_FORMAT,aDateTime);
  end;
  DateSeparator:= D;  
end;



To get the Date on a proper format in my xml.

How can i do the reverse?  Unformat it back to a TDateTime?

0
Comment
Question by:wqclatre
[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
  • 3
  • 2
  • +1
10 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 17979024
maybe something like (not tested):

function XMLStrToDate(aDateTime: string): TDateTime;
var
 d : Char;
begin
  d:= DateSeparator;
  DateSeparator:= XML_DATE_SEPARATOR;

  if aDateTime = '' then
  begin
    Result:= 0
  end else
  begin
    DateTimeToString( Result, XML_DATE_FORMAT, aDateTime);
  end;
  DateSeparator:= D;  
end;
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 17979037
you will have to do it manually by getting the rigth parst from your string in XML_DATE_FORMAT and using EncodeDateTime()
If you tell me what XML_DATE_FORMAT is I'll make you a start.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 17979056
too late :)
cool I didn't know of DateTimeToString (strange name btw, how about StringToDateTime)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:wqclatre
ID: 17979251
I think I was to early to Grade this:

DateTomeToString looks like:


IE IT expect a String not a TDateTime as the first parameter:

I solved it by:
var
 FS : TFormatSettings;
 LCID : Integer;
begin
  LCID:= GetUserDefaultLCID;
  GetLocaleFormatSettings(LCID,FS);
  FS.DateSeparator:= XML_DATE_SEPARATOR;
  FS.ShortDateFormat:= XML_DATE_FORMAT;
  Result:= StrToDateTime(aDateTimeString,FS)
0
 
LVL 28

Expert Comment

by:2266180
ID: 17979273
>IE IT expect a String not a TDateTime as the first parameter:

of course it does: you did ask for the reverse, did you not? reverse of
function DateToXMLStr(aDateTime: TDateTime): string;
is
function XMLStrToDate(aDateTime: string): TDateTime;

so I don't see where the problem is. StrToDateTime also takes a string as first parameter.
0
 
LVL 28

Expert Comment

by:2266180
ID: 17979295
oh. my bad. you are correct. I just looked through the help and don't know what in the world I was thinking when copy pasted datetimetostring.
0
 
LVL 2

Author Comment

by:wqclatre
ID: 17979299
Result : TDateTime;

Try sending in result into StringToDateTime ????????

DateTimeToString( Result, XML_DATE_FORMAT, aDateTime)  ??????


Won't work....


0
 
LVL 28

Expert Comment

by:2266180
ID: 17979303
btw, you should post a comment in community support asking for a reopan and paq with points refund.
0
 
LVL 2

Author Comment

by:wqclatre
ID: 17979313
Posted at the same time here.

Well I did the same. Graded without reading so you are not the only one here ;-)

However. Problem solved.....
0
 
LVL 1

Accepted Solution

by:
kodiakbear earned 0 total points
ID: 18003994
Closed, 500 points refunded.
kb
Experts Exchange Moderator
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
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…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

743 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