add time from database table

how can i sum all time from database table

Page 1 of 1

4 Replies - 2818 Views - Last Post: 15 May 2009 - 03:24 AM Rate Topic: -----

#1 anirai  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 14-May 09

add time from database table

Posted 15 May 2009 - 12:53 AM

Try
			Using connection As New SqlConnection("server=localhost;database=abc;uid=sa;password=;")
				Using command As New SqlCommand("SELECT sum(late_time) FROM log , connection)
					connection.Open()
					Dim totallatetime As Double = CDbl(command.ExecuteScalar())
					'Use totalQuantity here.
					TextBox13.Text = totallatetime

					' connection.Close()

				End Using
			End Using
		Catch ex As SqlException
			For Each er As SqlError In ex.Errors
				MessageBox.Show(er.Message)
			Next
		End Try

this what do for summing total records....when it's integer it's fine ..but i m doing summing for time...late_time is datetime...it gives me error..how can i add all total time from ltae_time column....???

Is This A Good Question/Topic? 0
  • +

Replies To: add time from database table

#2 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 404
  • View blog
  • Posts: 2,983
  • Joined: 18-September 06

Re: add time from database table

Posted 15 May 2009 - 02:22 AM

You can't use sum on a date.
Was This Post Helpful? 0
  • +
  • -

#3 anirai  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 14-May 09

Re: add time from database table

Posted 15 May 2009 - 02:38 AM

ya ...n how can i add time then from database?
Was This Post Helpful? 0
  • +
  • -

#4 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: add time from database table

Posted 15 May 2009 - 02:38 AM

hello,
try to get the datediff between the max and min dates
something like:
select datediff(minute,min(late_time),max(late_time)) from log



Edit: this will return the the minutes between the first date and the last date.
you can use [hour] or [day] ... to return what you need,
for more information, read about DATEDIFF function

This post has been edited by ahmad_511: 15 May 2009 - 02:44 AM

Was This Post Helpful? 0
  • +
  • -

#5 anirai  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 14-May 09

Re: add time from database table

Posted 15 May 2009 - 03:24 AM

okay..thanks a lot
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1