Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb.net code behind asp.net 4, Error converting double to date

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I am trying to build a date using DateSerial but some of the numbers/Variables it's not liking. Day(WeekEndDay - (6 - DayNumber)))
I get one of two errors.
1. can't convert integer to date.
2. Conversion form type double to date is invalid.
so How can I convert or cast this?
Code:
   Public Function WhichDate(ByVal DayNumber, ByVal WeekEndDate)

        ' figure out which date by the day number of the week.
        Dim Today, TheDay As Integer
        Dim WeekEndDay As Integer = Day(WeekEndDate)
        'Dim WeekEndMonth = Month(WeekEndDate)
        'Dim WeekEndYear = Year(WeekEndDate)
        Dim WhichDate1 As Date
        Try
            If WeekEndDate <> DetermineWeekEndingDate("justdate") Then

                WhichDate1 = DateSerial(Year(WeekEndDate), Month(WeekEndDate),[COLOR=red] Day(WeekEndDay - (6 - DayNumber)))[/color]
            Else
                Today = Now.DayOfWeek
                TheDay = Today - DayNumber
                WhichDate1 = DateSerial(Year(Now), Month(Now), Day(Now) - TheDay)
            End If
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Information, "Error")
        End Try


        WhichDate = WhichDate1

    End Function

I also tried changing that line to: but get squgilly under it saying "can't convert integer to date."
Code:
                Dim NewDay As Integer = WeekEndDay - (6 - DayNumber)
                WhichDate1 = DateSerial(Year(WeekEndDate), Month(WeekEndDate), Day(NewDay))

DougP
 
I figured this out. good or bad
changed it to a double and used > Date.FromOADate.
Code:
                Dim NewDay As Double = WeekEndDay - (6 - DayNumber)
                WhichDate1 = DateSerial(Year(WeekEndDate), Month(WeekEndDate), Day(Date.FromOADate(NewDay)))

DougP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top