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
 TIME IN 24 HRS FORMAT

Author  Topic 

devisetti
Starting Member

30 Posts

Posted - 2008-05-08 : 03:45:56
Hi

I have TIME stored in the column as

stime
-----
16:12:00
16:14:00
00:00:00
16:12:00
02:18:00

Required output :
1612
1614

I need to get its as in 24 hrs (not required seconds)
Ex:16:12

I am also require without semicolon Ex:1612

Many Thanks in advance

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-05-08 : 03:51:30
select convert(char(2),substring(stime,1,2)) + convert(char(2),substring(stime,4,2))
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-08 : 03:52:49
If time is stored as varchar (and time only)

SELECT REPLACE(LEFT(sTime, 5), ':', '')

If time is stored as datetime

SELECT REPLACE(CONVERT(VARCHAR(5), sTime, 108), ':', '')


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-08 : 03:56:00
Is this for display purpose? If yes, its better to do this in your front end application.
ANd if you want really to do it in SQL Server,try thi:-

SELECT LEFT(REPLACE(CONVERT(varchar(10),DateColumn,108),':',''),4) FROM YourTable
Go to Top of Page

devisetti
Starting Member

30 Posts

Posted - 2008-05-08 : 04:04:01
Thanks very much guys. Its working fine.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-08 : 04:26:21
IF you use front end application, do this formation there
If you use datetime column

select datepart(hour,col)*100+datepart(minute,col) from your_table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-08 : 04:29:05
Will that include leading zero if time is before 10 am?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -