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 2000 Forums
 SQL Server Development (2000)
 how to get AM or PM Time?

Author  Topic 

Clages1
Yak Posting Veteran

69 Posts

Posted - 2008-07-30 : 10:30:14
Hi I have a table with a Smalldatetime
if i do
"substring(Cast (mob1_emissao as Char(19)), 13,5) "
in this Column instead of 14:43:00 i get 2:43
I would like to get 14:43

Tks
Clages


2008-01-25 14:43:00 2:43
2008-01-25 15:25:00 3:25
2008-01-25 18:36:00 6:36
2008-01-25 11:20:00 11:20
2008-01-25 15:15:00 3:15
2008-01-25 18:44:00 6:44
2008-01-25 19:01:00 7:01
2008-01-25 15:35:00 3:35
2008-01-25 18:56:00 6:56

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-30 : 10:37:32
use convert() see http://msdn.microsoft.com/en-us/library/ms187928.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-30 : 10:41:08

SELECT CONVERT(VARCHAR(20), GETDATE(), 100)
Go to Top of Page

Clages1
Yak Posting Veteran

69 Posts

Posted - 2008-07-30 : 17:11:24
CONVERT(VARCHAR(20), mob1_emissao, 100)
Doenst work because i get 2:43PM and I Need 14:43
In the Grid I can not get AM/PM , only de time

Ok , Now i am adding 12 to the time
but i am looking for a better solution

Tks

CLages

Original Column Converted Column
2008-01-25 11:20:00 Jan 25 2008 11:20AM
2008-01-25 14:43:00 Jan 25 2008 2:43PM



Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-30 : 17:14:35
The best solution is to do this formatting in your application and not in SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-07-30 : 17:33:29
[code]
select DT = convert(varchar(19),getdate(),121)

Results:
DT
-------------------
2008-07-30 17:32:44

(1 row(s) affected)
[/code]

CODO ERGO SUM
Go to Top of Page

Clages1
Yak Posting Veteran

69 Posts

Posted - 2008-07-31 : 18:59:58
tks,
Now working fine
Clages1
Go to Top of Page
   

- Advertisement -