Solved

Example to use DTPicker control to display 2 dates

Posted on 2006-11-28
4
307 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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