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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 datepicker components / get dayspan

Status
Not open for further replies.

safra

Technical User
Jan 24, 2001
319
NL
Hi,

Still new with Delphi and experimenting with the datepicker component. I have two datepickers on the form and I would like to calculate the days between the 2 selected dates on the daypicker.I found the functions dayspan and daysbetween that work with a TDatetime. I tried to use it with the dates from the datepicker but didn't work. How do you use these functions for what I am trying to do?

I also searched for a function that will automatically return the date of the next day of a given date. Does it exist or can anyone explain how to do this in Delphi?

Kind regards,

Raoul

ah, also wondered if it is possible to replace that red circle that highlights today's date in the datepicker for something else (perhaps something similar as the way the selected date is highlighted but then another color or so)?

 
You should be able to do something like the following:
Code:
  ShowMessage('Fractional days difference = ' +
              FloatToStr(DaySpan(DTP1.Date, DTP2.Date)) + ' days');
OR
Code:
  var
    Difference: Double;
  begin
    ...
    Difference := DaySpan(DTP1.Date, DTP2.Date);
    ...
  end;
You could use DaysBetween in a similar way, instead of DaySpan depending on whether you need fractional or whole days as a result. I have assumed DTP1 and DTP2 are the names of the two TDateTimePicker components.

Clive [infinity]
 
Thanks,

When I do something like that I get:
Undeclared identifier: 'DaySpan'

Raoul
 
I'm pretty sure that DaySpan is in the DateUtils, add that to your uses clause and it should work. if not, highlight, DaySpan -> F1 and at the top of the help file it will tell you which component you need to add.

Leslie
 
Yes, it is working now. Leslie, thanks for the highlighting/F1 Tip.

Also found a way to increment a specific day with one day.

The only thing I still wonder about is if it is possible to change the layout of the day picker and then especially replacing the red circle around today's date into something similar as how the selected date is highlighted but then a different color. I have been looking for the location where the components are installed to see if the datePicker uses an image for the highlighting which perhaps can be replaced for another image. Could this be possible or anyone has another suggestion?

Thanks,
Raoul
 
I'm afraid it doesn't look to hopeful. Here's a quote I found on another site "The DateTimePicker is a Windows common control...Delphi's wrapper simply handles the messaging usually used to work with this control."

On MSDN I found that the DateTimePicker Windows control has the following properties:
CalendarBackColor
Color to be used for the DateTimePicker's background.
CalendarForeColor
Color to be used for the DateTimePicker's foreground, the color of the text caption.
CalendarTitleBackColor
Customize calendar title background color.
CalendarTitleForeColor
Customize calendar title foreground color.
CalendarTrailingForeColor
Color of dates that preceded and follow the displayed month or months.

But none of these seem to match what you want to change.

I would suggest looking on Torry.net for a component that is more customisable.

Hope this helps!

Clive [infinity]
 
Thanks Clive, the link to experts-exchange is hanging. I will try later. Yes, I also found It is very good and most of the functions come with examples.

Raoul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top