Home Forums SQL Server 7,2000 T-SQL convert military time to standard time RE: convert military time to standard time

  • I think it's because of where you're including the replicated 0's.

    This will work:

    DECLARE @MilDate VARCHAR(20)

    SET @MilDate = '13:38'

    SET @MilDAte = REPLACE( @MilDate, ':', '')

    SELECT @MilDate

    SET @MilDate = LEFT( @MilDate + REPLICATE( '0', 6), 6)

    SELECT @MilDate AS Timevalues

    SET @MilDate = STUFF( STUFF( @MilDate, 3, 0, ':'), 6, 0, ':')

    SELECT @MilDate

    SELECT CONVERT( VARCHAR(25), CONVERT( DATETIME, @MilDATE), 100)

    EDIT: I lied, close, but jumped the gun. Formatting is off when I apply it to convert to style 100. Back in a minute or two.

    Heh, beat myself up with a typo, whoops. All's good.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA