Solved

TDateTime

Posted on 2000-04-25
8
432 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

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

18 Experts available now in Live!

Get 1:1 Help Now