Solved

FormatDateTime with NULL Date Fields

Posted on 2004-04-10
5
503 Views
Last Modified: 2010-04-05
Hi all,
  When using FormatDateTime routine with a NULL Date fields, this function return 30/12/1899.
  So, How to avoid this undesirable value.

Thanks,
Khalid.
0
Comment
Question by:Qosai_DBA
[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
  • 3
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 30 total points
ID: 10795976
if dataset.fieldbyname('DateFieldName').isNull then
  result := ''
else
  result := formatDateTime(...);

meikl ;-)
0
 
LVL 1

Author Comment

by:Qosai_DBA
ID: 10796505
Hi kretzschmar,
  Your example is correct when use FormatDateTime with Database Fields, but what can I do when using variables of TDateTime as a datatype with no value?

Thanks,
khalid.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10796518
if datevalue = 0 then
  result := ''
else
  result := formatDateTime(...);

meikl ;-)
0
 
LVL 1

Author Comment

by:Qosai_DBA
ID: 10800020
Hi again,
I'm sorry kretzschmar, maybe I'm facing some problem.
this's my code

procedure TForm1.Button1Click(Sender: TObject);
var v_Date: TDatetime;
begin
  if(v_Date = 0)then
    Form1.Label1.Caption:= ''  // Return 30/12/1899
  else
    Form1.Label1.Caption:= FormatDateTime('dd/mm/yyyy', v_Date);
end;

Thanks,
Khalid.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10800126
well khalid,

which value should v_date have?
(currently it may random, because of a local uninitilaized var)

meikl ;-)
0

Featured Post

Industry Leaders: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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