Solved

TDateTime

Posted on 2000-04-25
8
434 Views
Last Modified: 2010-04-04
Hi,
I have a problem with "mixing" a Date (given from a TMonthCalendar) and a Time (given indirectly from a TEdit) to one TDateTime-Value.

The MonthCalendar returns a TDateTime-Value with the current or specified Date (which is good) and also with the current Time (which is no good)

eg. 25.04.00, 15:54:00

and the StrToTime(Edit1.Text) returns the Time only (which is enough for me)

31.12.1899 (or something), 16:00:00

but when i simply add those two DateTime-Values I get something completly weird. So how would i mix the Date from the MonthCalendar with the Time from the Editbox to

25.04.00, 16:00:00

I think it cant be that hard, but im not really familiar with TDateTime...
0
Comment
Question by:omsec
8 Comments
 
LVL 2

Expert Comment

by:craig_capel
ID: 2747619
edit1.text:=datetimetostr(now);

Try that...
0
 
LVL 5

Accepted Solution

by:
TheNeil earned 10 total points
ID: 2747638
Try this:

dtTime := StrToTime(Edit1.Text);
dtDate := MonthCalendar.Date;

dtFinal := TRUNC(dtDate) + (dtTime - TRUNC(dtTime));

What it does is use the time from your edit box and the date from your calendar component. TDateTime is basically a real value, with the integer part specifying the date, and the fractional part specifying the time. The above code just adds them together

The Neil =:)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2747674
the neil, you just said it

dtTime := StrToTime(Edit1.Text);
dtDate := MonthCalendar.Date;

dtFinal := TRUNC(dtDate) + (FRAC(dtTime));

meikl

0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2747749
Either I got it right or there's someone else out there as confused and lost as I am

The Neil =;)

PS. Thanks for pointing out FRAC - I didn't know about that
0
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.

 

Expert Comment

by:CoreEye
ID: 2748007
U can try this;

strTime:string;
strDate:string;
dtFinal : TDateTime;

strTime := Edit1.Text;
strDate := DateToStr(MonthCalendar.Date);

dtFinal := StrToDateTime(strDate + ' ' + strTime);


0
 
LVL 2

Author Comment

by:omsec
ID: 2750277
i think theNeil gave me the pointer :)
I'm gonna test it now...
0
 
LVL 2

Author Comment

by:omsec
ID: 2750496
CoreEye: The solution using numeric data types only might be more efficient since the CPU proceeds operations faster on these types than it does on strings - TheNeil's code does the job fine and quickly and he posted his text first, i think he deserved the points, altought it's not much :)
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2750530
Thanks Omsec. All points gratefully received

The Neil =;)
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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

19 Experts available now in Live!

Get 1:1 Help Now