?
Solved

Assign a date to TDateTimePicker

Posted on 2006-06-05
5
Medium Priority
?
397 Views
Last Modified: 2010-04-05
Hi have a DateTimePicker box on a form.  

If I read a date field from an access database in the format of yyyy/MM/dd and assign it to a string variable called, DateCreated, how can I assign this value to the DateTimePicker I have on the form?

Hope there are some helpers out there....
0
Comment
Question by:zork007
5 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 300 total points
ID: 16831429
something like this should help:
var s:string; d:tdatetime; fs:tformatsettings;
begin
  s:='2006/05/25';
  fs.ShortDateFormat:='y/m/d';
  fs.DateSeparator:='/';
  d:=StrToDate(s,fs);
  showmessage(datetostr(d));
end;
0
 
LVL 5

Expert Comment

by:Scay7
ID: 16835873
You can assign the datetimepicker like so

datetimepicker1.Date := strtodate(*your format of yyy/mm/dd as a string*);

Peace Scay7
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 16836997
var
  DateCreated : string;
  OldShortDateFormat : string;
  OldDateSeparator : char;
begin
DateCreated := '2008/10/07'; // here's your date in "yyyy/mm/dd" format
OldShortDateFormat := ShortDateFormat; // store old format
OldDateSeparator := DateSeparator; // store old date separator
ShortDateFormat := 'yyyy/mm/dd'; // change format of short date
DateSeparator := '/'; // change date separator
DateTimePicker1.Date := StrToDate(DateCreated); // convert date, assign it to DateTimePicker
ShortDateFormat := OldShortDateFormat; // restore date format
DateSeparator := OldDateSeparator; // restore date separator
end;
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16837763
why wouldn't you get the date field as a TDateTime?
e.g.
var mydate: TDateTime;
begin
    mydate := MyField.AsDateTime;
    datetimepicker1.datetime := mydate;
0
 

Author Comment

by:zork007
ID: 16840705
Thanks for your help.  Would have liked a simple solution like the one that TheRealLoki suggested but kept getting the error that the date wasn't a valid format.

So I have to give the points to ciuly for the easiest solution.  :o)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses

755 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