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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Get subString

Author  Topic 

abhi123
Starting Member

10 Posts

Posted - 2009-06-01 : 15:13:01
Hi
i need to get a string from hours. For example, if the hours is 12:48, then i need
h = 12 and
m = 48
but if the hours is 6:49 then i need
h = 6
m = 48

i tried left and right functions for it but how do i know that hours are two digits or a single digit.
Thanks
Abhishek

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-01 : 16:01:25
SELECT DATEPART(HOUR, @value), DATEPART(MINUTE, @value)



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

eralper
Yak Posting Veteran

66 Posts

Posted - 2009-06-08 : 09:34:20
Hello all,

If we are working time data type, we can work on the below sample which changes with the AM/PM values


DECLARE @t1 time = '6:40 AM'
DECLARE @t2 time = '6:40 PM'
SELECT
DATEPART(HOUR, @t1), DATEPART(MINUTE, @t1),
DATEPART(HOUR, @t2), DATEPART(MINUTE, @t2)



-------------
Eralper
http://www.kodyaz.com
Go to Top of Page
   

- Advertisement -