Solved

FormatDateTime with NULL Date Fields

Posted on 2004-04-10
5
483 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

861 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now