Solved

FormatDateTime with NULL Date Fields

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

22 Experts available now in Live!

Get 1:1 Help Now