Link to home
Start Free TrialLog in
Avatar of omsec
omsec

asked on

TDateTime

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...
Avatar of craig_capel
craig_capel

edit1.text:=datetimetostr(now);

Try that...
ASKER CERTIFIED SOLUTION
Avatar of TheNeil
TheNeil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kretzschmar
the neil, you just said it

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

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

meikl

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
U can try this;

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

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

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


Avatar of omsec

ASKER

i think theNeil gave me the pointer :)
I'm gonna test it now...
Avatar of omsec

ASKER

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 :)
Thanks Omsec. All points gratefully received

The Neil =;)