Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# TDateTime

Posted on 2000-04-25
Medium Priority
450 Views
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
Question by:omsec
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

LVL 2

Expert Comment

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

Try that...
0

LVL 5

Accepted Solution

TheNeil earned 40 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

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

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

Expert Comment

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

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

LVL 2

Author Comment

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

ID: 2750530
Thanks Omsec. All points gratefully received

The Neil =;)
0

## Featured Post

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
###### Suggested Courses
Course of the Month7 days, 1 hour left to enroll

#### 704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.