BCP Raw datafile format for a datetime2(3)

  • I have inherited a data collection system that generates raw BCP files that are loaded into SQL server 2008. However, I need to modify this to cater for loading into a table that contains a datetime2(3) column.

    Does anybody know how this type of data is encoded within a raw BCP file?

  • I just discovered the answer...

    The Microsft Sql Server/100/Tools/Binn/bcp.exe utility uses the following format when writing out a datetime2 value in native raw format (bcp options -CRAW -n):

    If this value is a null then the single byte 0xFF is written out.

    Otherwise:

    A single byte 0x08 to indicate a datetime2 value

    Followed by 5 bytes that represent the number of Ticks (100 nano-seconds) within the time part of the value. These bytes are written out in the order LSB -> MSB.

    Followed by 3-bytes that represent the number of days since 01 Jan 0001. Again these bytes are written out in the order LSB -> MSB.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply