Solved

TDateTime

Posted on 2000-04-25
8
446 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
[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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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