How can I convert SQL time using a datetime stamp to milliseconds.
I am doing a highstock chart using VB.Net
and this is my selection code so far
Dim mydatalist As New List(Of XyData)
Dim sqlReader As SqlDataReader
Dim strConn As New SqlConnection(ConfigurationManager.ConnectionStrings("myCipConnection").ConnectionString)
Dim strSql As String = "SELECT TOP 1000 DATEDIFF(second,{d '1970-01- 01'},dtmStamp)AS dtmStamp ,dblReturnTemp FROM tblCIPEventData "
Dim sqlCmd As New SqlCommand(strSql, strConn)
strConn.Open()
sqlReader = sqlCmd.ExecuteReader
I have a SQL selection
Dim strSql As String = "SELECT TOP 1 dtmStamp ,dblReturnTemp FROM tblCIPEventData"
The result looks like
2009-10-22 11:29:31.513
How can I convert this to milliseconds
To figure out the milliseconds of a date you first have to compare it to some other DateTime. By subtracting two DateTime objects you will end up with a TimeSpan object. Then that TimeSpan object can be converted to milliseconds. This can all be done with one simple line of code: