Charlie Stuart
Charlie Stuart

Reputation: 272

Using DatePicker to get the current day within the year in VB.NET?

I am currently programming a new Windows Phone Application and within this app i want the user to be able to find the hex date for any date of their choice. For this reason i am letting the user use a date picker to choose their desired date. Before i included the date picker i was allowing the user to get the hex date for today's date by using the following code:

        ReverseString = 365 - DateTime.Today.DayOfYear
        txtReverseJulian.Text = ReverseString.PadLeft(3, "0")

However now i can't use the DateTime function because i am letting them choose a date from the date picker, how can i change this code so that it will work?

Thank you

Upvotes: 0

Views: 1435

Answers (2)

dbasnett
dbasnett

Reputation: 11773

I am guessing at what you are trying to do... Could you provide clarification?

    Dim foo As DateTime = New DateTime(DateTime.Today.Year, 12, 31) 'last day of the current year
    Dim ldoy As Integer = foo.DayOfYear 'number of days in year
    Dim dr As Integer = ldoy - DateTime.Today.DayOfYear 'number of days until end of year

Using a DatePicker

    Dim foo As DateTime = New DateTime(aDatePicker.Value.Year, 12, 31) 'last day of the current year
    Dim ldoy As Integer = foo.DayOfYear 'number of days in year
    Dim dr As Integer = ldoy - aDatePicker.Value.DayOfYear 'number of days until end of year

Upvotes: 1

Jaihind
Jaihind

Reputation: 2778

This may help you

//Here is event fire when datepicker value will be change
 ValueChanged="DatePicker_ValueChanged"
Private Sub DatePicker_ValueChanged(sender As Object, e As DateTimeValueChangedEventArgs)
ReverseString = e.NewDateTime.Value.ToString()
End Sub   
txtReverseJulian.Text = ReverseString.PadLeft(3, "0")

Upvotes: 0

Related Questions