SQL Server 2K CONVERT() question

Results 1 to 2 of 2

Thread: SQL Server 2K CONVERT() question

  1. #1
    Join Date
    Dec 1969

    Default SQL Server 2K CONVERT() question

    Hi all:<BR><BR>Why are there no CONVERT() functions to pull a time value from a DateTime field as: 12:15 PM? Why does this seemingly simple formatting seem to be a Holy Grail of data?<BR><BR>I can get the PORTION correct with CONVERT(X, X, 100), but that means I still have to jump through more hoops to get just an AM/PM time. Why?<BR><BR>Kurt

  2. #2
    Join Date
    Dec 1969

    Default Good question...

    Bet you&#039;ll be glad when Yukon really arrives and you can use anything in the CLR instead of just the built-in SQL functions.<BR><BR>But...<BR><BR>Why couldn&#039;t you write your own TSQL function, today?<BR><BR>Use CONVERT(VARCHAR, x, 100) and then use SUBSTRING on that.<BR><BR>CREATE FUNCTION hms( @dt AS DATETIME ) RETURNS VARCHAR(8)<BR>BEGIN<BR> RETURN SUBSTRING( CONVERT( VARCHAR(30), @dt, 100 ), 13, 7 )<BR>END<BR><BR>If I counted the characters right.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts