Reputation: 3
I have a date/time field in a database table, i want to calculate the time difference between the date/time in table and the current date/time
For example: i want to show in the vb forum 2 Days 10 Hours Remaining
If it doesnt work for both time and date, how to do it for date only?
Thank You
Upvotes: 0
Views: 1276
Reputation: 1110
You can also do this in the database,
SELECT (CURRENT_TIMESTAMP - '2012-12-04T20:00:00')
You can replace the hard coded date and time with a datetime column.
Upvotes: 0
Reputation: 43743
If you load the have the data already loaded into a Date
(DateTime
) object, then you can just do it like this:
Dim loadedDate As Date = ...
Dim span As TimeSpan = Date.Now - loadedDate
Console.WriteLine("{0} Days {1} Hours Remaining", span.Days, span.Hours)
Upvotes: 3