Solved

Example to use DTPicker control to display 2 dates

Posted on 2006-11-28
4
303 Views
Last Modified: 2012-05-05
I would like to calculate begindate and enddate using the DTPicker conteol in VB.Net.
Can someonw show an example how to build it?
0
Comment
Question by:zachvaldez
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:Hillwaaa
Hillwaaa earned 100 total points
ID: 18034642
Hi zachvaldez,

Can you use two dtpickers?  If so just do:
   Dim start_date As Date
   Dim end_date as Date

 
    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        start_date = Me.DateTimePicker1.Value
    End Sub

    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
        end_date = Me.DateTimePicker2.Value
    End Sub

Cheers,
Hillwaaa
0
 

Author Comment

by:zachvaldez
ID: 18035921
I really not sure if this is the best route to go. I plan of putting a date range in two textboxes. But I would like to click an object to display a calendar then select a particular date then that number will entered to a textbox for the begin date . The same is true also in putting an enddate. The result of it . There will be 2 controls showing the begin date and end date.
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 18036401
You just use Hillwaaa's code like this
to calc the number of days.

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        start_date = Me.DateTimePicker1.Value
        TextBox1.Text = start_date.ToString()
    End Sub

    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
        end_date = Me.DateTimePicker2.Value
        TextBox2.Text = end_date.ToString()
        TextBox3.Text = (end_date.Date.Subtract(start_date.Date).Days).ToString

    End Sub
0
 
LVL 18

Accepted Solution

by:
vbturbo earned 100 total points
ID: 18037284
And here is how to create a dynamic datepicker

Imports System.Windows.Forms

' Create a new DateTimePicker control and initialize it.
Dim DateTimePicker1 As New DateTimePicker()
Dim DateTimePicker2 As New DateTimePicker()

Dim start_date As Date
Dim end_date as Date

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click    
    ' Set the MinDate and MaxDate.
    DateTimePicker1.MinDate = New DateTime(1969, 11, 29)
    'DateTimePicker1.MaxDate = DateTime.Today
   
    ' Set the CustomFormat string.
    DateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"
    DateTimePicker1.Format = DateTimePickerFormat.Custom
   
    ' Show the CheckBox and display the control as an up-down control.
    DateTimePicker1.ShowCheckBox = True
    DateTimePicker1.ShowUpDown = True

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click    
    ' Set the MinDate and MaxDate.
    DateTimePicker2.MinDate = New DateTime(1969, 11, 29)
    'DateTimePicker2.MaxDate = DateTime.Today
   
    ' Set the CustomFormat string.
    DateTimePicker2.CustomFormat = "MMMM dd, yyyy - dddd"
    DateTimePicker2.Format = DateTimePickerFormat.Custom
   
    ' Show the CheckBox and display the control as an up-down control.
    DateTimePicker2.ShowCheckBox = True
    DateTimePicker2.ShowUpDown = True

End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        start_date = Me.DateTimePicker1.Value
        TextBox1.Text = start_date.ToString()
    End Sub

    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
        end_date = Me.DateTimePicker2.Value
        TextBox2.Text = end_date.ToString()
        TextBox3.Text = (end_date.Date.Subtract(start_date.Date).Days).ToString

    End Sub

Is this what you mean ?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now