Difference Between Two Time In Database

retkehing

Well-known member
Joined
Feb 5, 2006
Messages
153
Programming Experience
Beginner
Currently, i have start time and end time stored in database, the start time and end time format are h:mm:tt, is there any way for me to find the difference between the start time and end time? Thank you.
 
Does this need to be in SQL? If so, there is a date difference function in most DB's.

If not, in .NET:

VB.NET:
Dim ts As Timespan = date2 - date1

Then all you need to do is use the properties of ts to get the number of days, hours, etc.

BTW, .NET is pretty good at parsing date/time formats via Date.Parse or Convert.ToDateTime. ;)

Cheers,
-Steve
 
Apart from that, which function can be used to compare the time and i want to display the earlier one in first row in datagridview and so on.

I am able to use the following code to display the today date. How to do the same thing to time? I found that i can dim it as datetime and equal to now, but i only want the time part but now the whole complete date and time. Thank you.

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] datTim2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2] = Format(Today, [/SIZE][SIZE=2][COLOR=#800000]"dd/MM/yy"[/COLOR][/SIZE][SIZE=2])
[/SIZE]
 
Last edited:
Back
Top