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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateAdd Question 1

Status
Not open for further replies.

PsychoCoder

Programmer
May 31, 2006
140
US
In my application I have these 2 functions (yes they were posted in a previous post)

Code:
Public Function GetGMTOffset(ByVal sAirport As String) As Double
        Dim dOffset As Double
        sSQL = "EXECUTE ama_GetGMTOffset @airport"
        cmdCommand = New SqlCommand(sSQL, cnConnection)
        cmdCommand.Parameters.AddWithValue("@airport", sAirport)
        Try
            cnConnection.Open()
            dOffset = cmdCommand.ExecuteScalar
            Return dOffset
        Catch exSQL As SqlException
            MsgBox(SQL_EXCEPTION, MsgBoxStyle.Critical, "Database Error")
        Catch exSQLTimeout As TimeoutException
            MsgBox(SQL_TIMEOUT, MsgBoxStyle.Critical, "Timeout Error")
        Catch exApp As ApplicationException
            MsgBox(APP_EXCEPTION, MsgBoxStyle.Critical, "Application Error")
        Catch ex As Exception
            MsgBox(GENERAL_EXCEPTION & ex.Message, MsgBoxStyle.Critical, "General Error")
        Finally
            cnConnection.Close()
        End Try
    End Function

Code:
 Public Function ConvertGMT(ByVal dLocalDate As DateTime, ByVal sAirport As String) As DateTime
        _dGMTTime = DateAdd(DateInterval.Hour, CType(GetGMTOffset(sAirport), Double), dLocalDate)
        Return _dGMTTime
    End Function

When the ConvertGMT function is called it works great, unless the offset is a floating point number (ie; 9.5), then it adds the 9 but not the .5. Anyone got any ideas?

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"In the new millennium there will be two kinds of business; those on the net and those out of business"

~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Code:
dim iSeconds as integer = CType(GetGMTOffset(sAirport), Double) * 360
_dGMTTime = DateAdd(DateInterval.Seconds, iSeconds, dLocalDate)
Return _dGMTTime

Use seconds instead of hours.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
ThatRickGuy,

I tried you suggestion and it still isnt right. For local time it is 10:48:50, then converted it should have been 11:18:50 but it was 11:45:50 (only 3 minutes not 1/2 an hour).

Any ideas on why this is happening?

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"In the new millennium there will be two kinds of business; those on the net and those out of business"

~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
ThatRickGuy,

Heres what I had to use to solve my dilema:

Code:
Dim iSeconds As Integer = CType(CType(GetGMTOffset(sAirport), Double) * (60 * 60), Integer)

Doing it that works perfect (dont ask me why but it does, when using * 360 it does't work but using (60 * 60 does.) Thanks for putting me on the right path, star for you.

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"In the new millennium there will be two kinds of business; those on the net and those out of business"

~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
ThatRickGuy,

I figured that out after I read my last post lol.

Thanks

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"In the new millennium there will be two kinds of business; those on the net and those out of business"

~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top