Solved

Example to use DTPicker control to display 2 dates

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WPF issue with Trigger 2 69
Handling arrays 14 35
Incorrect group by on LINQ query 5 27
Loop through Multiple Processes Async 2 17
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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

11 Experts available now in Live!

Get 1:1 Help Now