Hi I have managed to connect to an MS SQL server successfully but now I want to search records based on date and datetime can you please help me with providing the SQL Server with the correct datetime type?
The MS SQL Server fields where the datatime is stored is as below
Column Name Data Type
DATEARRIVED datetime
Example data
DATEARRIVED COLLFROM REGISTRATION PARTNUMBER 2018-11-13 12:26:00.000 Company A YR64 NZF 212 0300
In MS SQL Server the date and Datetime can be stored in one of serveral data types i.e. date, datetime, datetime2(7), datetimeoffset(7). When searching using .Net you can use convert(datetime, '01/01/2018',103) or by using datetime parameters you can send the datetime as '01/01/2018'.
There are a bunch of date functions in T-SQL that will give you days, hours, etc - so I'd recommend looking up a T-SQL language reference for more info.
Try Googling "Searching dates with T-SQL" for more info.
Also this VB.NET code (part of a class of mine - easily convertible to C# if you are a c# guy) will be extremelly useful to your case:
B4X:
Public Shared Function GetAndroidDateFromDatetime(dt As DateTime) As Long
Dim dtUnix As DateTime = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
Dim ts As New TimeSpan
ts = dt.Subtract(dtUnix)
Return ts.TotalMilliseconds
End Function
Public Shared Function GetDatetimeFromAndroidDate(lngDate As Long) As DateTime
Dim dtUnix As DateTime = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
Return dtUnix.AddMilliseconds(lngDate)
End Function