Click here to Skip to main content
13,802,976 members
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 11 Apr 2007
Licenced CPOL

Composite Date & Time Control

, 11 Apr 2007
Rate this:
Please Sign up or sign in to vote.
A control showing both date and time

Screenshot - CompositeDateTime_pic.jpg


This control displays the combined date and time, with calendar dropdown and updown arrows. It is basically two DatePicker controls merged using a SplitContainer. The splitter bar can be adjusted to give more room to either side.

This is my first attempt at such a control, so if there is another way, I'm open to suggestions.


The DatePicker control can display only date or time values. I currently use a combined date/time control in our MFC apps (BCGDateTime). When I moved to VS 2005, I couldn't find one written for .NET, so I tackled this.

Adding the control

Use Add Reference to add a reference to the DateAndTimeControls assembly in your project.

Add the control to the toolbox by right-clicking in a category and using Choose Items.

Screenshot - choose_item.jpg

Drag the control onto the form. The properties panel shows the new properties and events:

  • DateTimeValue - the default property of the control.
  • DateValue - just the date value of the control
  • TimeValue - just the time value of the control>
  • MinDate - the minimum date/time value for the control
  • MaxDate - the maximum date/time value for the control
  • DateFormat - the enumerated datepicker format value (ie long)
  • DateCustom - the custom format mask (ie dd-MMM-yyyy)
  • TimeFormat - the enumerated DatePicker format value (ie time)
  • TimeCustom - the custom format mask (ie hh:mi tt)
  • ValueChanged - the default event for the control. fired whenever the value is changed.

Using the control

To get a value from the control:

dim dt as Date
dt = DateTimeControl1.DateTimeValue
tTextbox1.Text = dt.ToString("dd-mmm-yyyy hh:mi tt")

To put a value in the control:

DateTimeControl1.DateTimeValue = Date.Now


Date.TryParse(TextBox1.Text, DateTimeControl1.DateTimeValue)

The constructor will give an error if the date is outside the MinDate-MaxDate range.

To clear the control:

DateTimeControl1.DateTimeValue = new Date(0L)

The date can also be cleared by typing <Backspace> in the control.

Points of Interest

Thanks to this project, I learned how to expose new class events to the outside world.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Richard Jones
Web Developer
Canada Canada
I have been developing applications at City of Moncton since 1992. My focus has been on C/C++ along with Oracle and SQL/Plus.

I've been tainted with Oracle Developer, and Palm development. ick.

I am actively developing in .NET 2015.

You may also be interested in...


Comments and Discussions

QuestionGood work Pin
pc180029-Nov-11 17:30
memberpc180029-Nov-11 17:30 
GeneralMy vote of 1 Pin
Member 824475119-Sep-11 0:45
memberMember 824475119-Sep-11 0:45 
GeneralThank you! Pin
Pranav Ainavolu19-Apr-11 3:29
memberPranav Ainavolu19-Apr-11 3:29 
QuestionHow to Set DateTimePicker value to Spaces [modified] Pin
treesprite21-Nov-10 16:56
professionaltreesprite21-Nov-10 16:56 
Nice control and it makes it easy to enter both date and time values without alot of fuss.

I have three Composite Date & Time controls on my form. On the first save of data only one of the fields needs to be populated.

But, if I don't enter data in two of the three controls I get a SQL Server overflow error because Spaces don't conform to the MIN and MAX settings.

Do you have a work around?

Today...I found that setting "tool tips" on the control does not work Frown | :(

modified on Monday, November 22, 2010 10:34 AM

GeneralCant use in Web Application Pin
satejprabhu18-Oct-07 20:34
membersatejprabhu18-Oct-07 20:34 
GeneralRe: Cant use in Web Application [links are flipped] Pin
Richard Jones19-Oct-07 3:11
memberRichard Jones19-Oct-07 3:11 
GeneralAnd Thanks from me too Pin
HRybko20-Jul-07 21:56
memberHRybko20-Jul-07 21:56 
GeneralThanks Pin 4:58 4:58 
GeneralRe: Thanks Pin
Richard Jones3-Jul-07 2:33
memberRichard Jones3-Jul-07 2:33 
Generalthanks Pin
raj34824-Apr-07 3:47
memberraj34824-Apr-07 3:47 
GeneralNice. Pin
Pete O'Hanlon13-Apr-07 5:36
protectorPete O'Hanlon13-Apr-07 5:36 
GeneralRe: Nice. Pin
Richard Jones13-Apr-07 7:26
memberRichard Jones13-Apr-07 7:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.181215.1 | Last Updated 11 Apr 2007
Article Copyright 2007 by Richard Jones
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid