Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert time to integers

Author  Topic 

cwildeman
Starting Member

40 Posts

Posted - 2012-03-16 : 16:12:06
I have two fields in an SQL Server table which are TimeCalled and TimeFinished and are datetime. I have an MS Access front end with text boxes where a user enters military time into both boxes. For instances they may enter 17:20 for TimeCalled and 17.30 for TimeFinished with ten minutes being the difference between the two. I want to create a query in SQL Server that converts these two times into an integer (i.e. 10). What is the best way to do this?
Thanks,


Chuck W

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-16 : 16:38:36
The best way is to not too...use formatting if you need to..

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

flamblaster
Constraint Violating Yak Guru

384 Posts

Posted - 2012-03-17 : 19:52:30
Wildeman, are you just trying to return a result to show the difference in minutes? If that's the case, you don't actually want to convert the times, you just need to use date functions:

select DATEDIFF(mi, Timecalled, TimeFinished)
from yourtable
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-18 : 10:43:24
quote:
Originally posted by cwildeman

I have two fields in an SQL Server table which are TimeCalled and TimeFinished and are datetime. I have an MS Access front end with text boxes where a user enters military time into both boxes. For instances they may enter 17:20 for TimeCalled and 17.30 for TimeFinished with ten minutes being the difference between the two. I want to create a query in SQL Server that converts these two times into an integer (i.e. 10). What is the best way to do this?
Thanks,


Chuck W


how do you want to show the minutes?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

cwildeman
Starting Member

40 Posts

Posted - 2012-03-18 : 18:53:47
I am going to do a further calculation. I want to sum the total minutes (the total date difference between the start and end date), and then divide by the count of account numbers to get a Time per Account number specified in minutes (i.e. 5.2 minutes per account number).

Chuck

Chuck W
Go to Top of Page

flamblaster
Constraint Violating Yak Guru

384 Posts

Posted - 2012-03-18 : 19:54:50
Did you try the datediff function that I posted above? The result between 1710 and 1720 would be 10 minute difference.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-19 : 00:18:53
quote:
Originally posted by cwildeman

I am going to do a further calculation. I want to sum the total minutes (the total date difference between the start and end date), and then divide by the count of account numbers to get a Time per Account number specified in minutes (i.e. 5.2 minutes per account number).

Chuck

Chuck W


so it will of float format or time format?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-19 : 10:21:38
Do you want to display the difference or store it.

If you want to display it, do it on the form

If you want to store it, forget that. The data will be stale as soon as you calculate it



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

cwildeman
Starting Member

40 Posts

Posted - 2012-03-20 : 11:18:04
Thanks for everyone's help. I tried select DATEDIFF(mi, Timecalled, TimeFinished) and it worked. I can do calculations off of this as well. Chuck


Chuck W
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-20 : 14:59:17
make sure you read this as well

http://www.sqlteam.com/article/datediff-function-demystified

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -