I suppose it depends where you want to handle the date manipulation.
1. Manipulate from sql, eg:
DATEDIFF(day, '10/10/2000', '12/10/2000')
Will return the amount of days between the two dates, you can choose any date/time modifier in the first parameter, day, hour, month, etc. You can also use other sql date manipulation functions, or create a function of your own to create specifics. You generally have to convert a date to string, but you don't have to convert a string to date; just as long as its syntactically correct.
2. Manipulate from vbnet:
This requires manipulating DATE objects, and if you want the same functionality, using a TIMESPAN object: eg,
Private d1 As Date = #10/10/2000#
Private d2 As Date = #12/10/2000#
Sub
Dim ts As TimeSpan
ts = d2.Subtract(d1)
Dim str As String = ts.TotalDays.ToString()
There are other useful timespan properties and methods. You should be aware however, unless you changed the datetime specific to your region on the database, the result will be month/day/year. This really screwed with my head until I realised it. This is'nt a problem with vb as it converts the date from the server. So it depends, server = less code but more overhead, vb = vice versa.
Enter your message below
Sign in or Join us (it's free).