Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having DateTimePicker Component difficulties

Status
Not open for further replies.

smitty654

Programmer
Jul 9, 2008
21
CA
I am using the DateTimePicker component to select a date that will later be submitted to a database on a design form. I am having difficulty in what to do to seperate the Date and Time into Weekday, Day, Month, and Year. I used the EncodeDate function to pull out the Date, Month, and Year values, but it needes specific values to Encode to get that information. I need these values and also the Weekday to use in the database. Any ideas on what functions that I may be missing or is there a better component for this this that will extract the information from a TDateTime Component? Thanks for any assistance.
 
There is a small array of functions.
Just as a disclaimer I am using BDS 2006.

[blue]DayOf (TDateTime)[/blue] will return a number between 1 and 31, with [blue]DayOfTheMonth[/blue] being the same function.
There is also [blue]DayOfTheWeek (TDateTime)[/blue] which returned a number between 1 (Monday) and 7 (Sunday).

There is [blue]MonthOf[/blue] / [blue]MonthOfTheYear[/blue] which function in the same manner. Passing them a TDateTime and they will return a number from 1 to 12.

For the Year, try [blue]YearOf[/blue]. Same style as above to use.

I am assuming you are already adding DateUtils to the [green]uses[/green] if you are using [blue]EncodeDate[/blue] to any capacity. An awesome thing at this point, since the functions I mentioned are very few of, would be to go to the Help files, and just search DateUtils. It should return all of the DateUtils routines. There are a few neat ones in there.

And these will work just fine with the TDateTimePicker. Let us know if you need anything else or if I misunderstood in any way.

~
Chuck Norris is the reason Waldo is hiding.
 
Thanks for the reply. Yes, before this I discovered (delphibasics.co.uk/RTL.asp?Name=DayOfTheWeek) to be a good resource for DateTime functions as well. Actually, I came across another problem. Here the sample output of the code(sorry, I don't know how to paste a block of code (such as <b> </b> in some message boards) in this forum):
procedure TForm3.btnConvertDateClick(Sender: TObject);
var
Weekday: TDateTime; // value used for DateTimePicker component
WeekdayNumConverted: TDateTime; // for the number to be converted to day
WeekdayConverted : string; // for the final result of the date converted t string
begin
WeekdayNumConverted := DayOfTheWeek(Weekday); // Day(number) of the Week converted from DateTimePicker
WeekdayConverted := DateTimeToStr(WeekdayNumConverted); //the previously converted number to a String of Text
edtConvertDate.Text := WeekdayConverted; the converted // This result is stored in the Text of the edit Control
end;

Perhaps I will make this a seperate post, but with this problem solved for this condition. Again, thanks for your help.
 
To post code you use the left brace [ and then the word 'code' followed by the right brace ]. When done you close it the same way you would an html, with the /code, except in the braces.
What exactly is the problem. You mention a problem, and list some code, but never state what the problem is.
I suppose I should probably start up delphi and just plug it in. =.=

~
Chuck Norris is the reason Waldo is hiding.
 
The problem I was having is that I didn't know how to convert a Date Property from a DateTimePicker component down to the weekday(i.e. Sunday, Monday, etc.), day, month, and year. I should have intended to indicate that this will eventually go to a database, but I figured out how to convert them later to strings for SQL code. I believe when I was using the "EncodeDate" function I may have been confused on what it expected. I apologize if I confused anyone in advance. ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top