Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Location
    Malaysia
    Posts
    5

    Smile Unanswered: DateTime format problem

    Hi,
    I have a datetime field that store data in format like this following format:
    2003-05-25 13:01:39.400

    How can I change the format of the of the datetime to 13:01:39.400 only.


    Thanks

  2. #2
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734
    SELECT CONVERT(VARCHAR,GETDATE(),114)

    This query will show you what all the datetime conversions look like. You can see why they look like they do by lookup up CONVERT in Books Online.

    SET NOCOUNT ON

    DECLARE
    @min INT,
    @max INT,
    @date DATETIME

    SELECT
    @min = 1,
    @max = 131,
    @date = GETDATE()

    SELECT @date

    WHILE @min <= @max
    BEGIN

    IF @min BETWEEN 15 AND 19
    OR @min = 26
    OR @min BETWEEN 27 AND 99
    OR @min BETWEEN 115 AND 119
    OR @min BETWEEN 122 AND 125
    OR @min BETWEEN 127 AND 129
    BEGIN
    GOTO NEXT_LOOP
    END

    SELECT @min, CONVERT(VARCHAR,@date,@min)

    NEXT_LOOP:

    SELECT @min = @min + 1
    END
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

Posting Permissions

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