?
Solved

Example to use DTPicker control to display 2 dates

Posted on 2006-11-28
4
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:Hillwaaa
Hillwaaa earned 400 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 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