Link to home
Start Free TrialLog in
Avatar of freddyho
freddyho

asked on

about date & time type

when i retriev the field(date, time) format) from access, delphi also display date&time togeter, but i only want them separately in my program.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

use the displayformat-property of the underlying TField
Avatar of Motaz
Motaz

If you want to extract only the Date form DateTime use Trunc, and if you want to use Time form DateTime use Frac. But you can ignore it example:

var
  MyDate: TDateTime;
  MyTime: TDateTime;
begin
  MyDate:= Trunc(Table1.FieldByName('Reg').AsDateTime);
  MyTime:= Frac(Table1.FieldByName('Reg').AsDateTime);
  ShowMessage(DateToStr(MyDate));
  ShowMessage(TimeToStr(MyTime));

The same will be fine if you use :

  MyDate:= Table1.FieldByName('Reg').AsDateTime;
  MyTime:= Table1.FieldByName('Reg').AsDateTime;

But the case will different if you want to compare two times such as:

if MyTime > YourTime then ...

In this case you muse use Frac to do comparison without Date

Motaz
Date
FormatDateTime('mm/dd/yyyy', Table1.FieldByName('TheField').AsDateTime);

Time
FormatDateTime('hh:nn:ss', Table1.FieldByName('TheField').AsDateTime);

In the first paramater you is how it will be displayed. You can arrange to display in any manner you want it to.
Or use
  Table1.FieldByName('TheField').AsDate
and
  Table1.FieldByName('TheField').AsTime
for any further handling of dates & times...
ASKER CERTIFIED SOLUTION
Avatar of VSF
VSF
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Greetings.
 
This question is still open today, perhaps it was overlooked or just lost in the volumes.  Please return to this question to update it with comments if more information is needed to get your solution.  If you've been helped by the participating expert(s), you may just convert their comment to the accepted answer and then grade and close.  If an answer has ever been proposed you may not have this option to accept the comment as answer, if that is the case, ask the specific expert you wish to award to post an answer.     This benefits others who then search our PAQ for just this solution, and rewards the experts who have provided information.  A win/win scenario.  Please DO NOT accept this comment as an answer,  it is merely a reminder.
 
If you wish to award multiple participants, you can do so by creating a zero point question in the Community Support topic area, include this link and tell them which experts you'd like to award what amounts.  If you'd like to delete this question, use the same process as above, but explain why you think it should be deleted.  Here is the Community Support link:   https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
You can always click on your profile to see all your open questions, in the event you also have other open items to be resolved.   If your number of Questions Asked is not equal to the number of Answers Graded, choose to VIEW question history, and you'll quickly be able to navigate to your open items to close them as well.
 
I've had excellent help from experts-exchange through the years and find the real key to getting what I need is to remain active in all my questions, responding with results to suggestions until my solution is found, and recommend that highly.
 
Thank you very much for your responsiveness, it is very much appreciated.  
":0)  Asta
 
P.S.  Some of the older questions from last year are not in the proper comment date order, and Engineering has been advised.  
SECOND REQUEST.

hi
i will be asking community support to close this question in 7 days.
i will be requesting that the points are split evenly for each commenter (except astaec and myself of course) .

Regards Barry

DO NOT ACCEPT THIS COMMENT AS ANSWER
A five-way split? On a fifty-point question?! Who's been talking to COBOLdinosaur?!?!

Per recommendation comment force/accepted by

Netminder
Community Support Moderator
Experts Exchange

kretzschmar: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20277945
Workshop_Alex: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20277953
CrazyOne: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20277955
Motaz: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20277957
<G>