Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004

    Unanswered: time format function or preceding zero's


    with the bcp (bulk copy program) I output some data to a file. The data consists of two columns which are datetime values and one column with the difference in time. For the difference calculation I use the DATEDIFF function. This function can only give the diff back in minutes or hours and not in a time format.

    Can I use a function to format the result or do I have to do it manually?

    I managed to do the calculation manually by using the % (mod) operator, but then I have the time in this format 0:0 where it should be in 00:00 or 00:00:00. In that case I need a function or a way to add preceding zero's to the values.

    Note that the formatting or manual calculation should be done in the SELECT clause to be able to use the bcp tool.

    Thanks in advance,

    Maarten de Jong
    Website developer

  2. #2
    Join Date
    Feb 2004
    Here is an example of how I zero fill.

    declare @i int
    set @i = 3
    select right('00' + cast(@i as varchar), 2)

  3. #3
    Join Date
    Nov 2002
    Not in datetime format...doesn't make sense....

    If the difference between 2 dates is 10 seconds, what date would that be?

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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