views:

622

answers:

2

I'm getting a hex string when converting a SPListItem's date.

eg. "0x01c9d2be|0x809a8800"

This question answers it.

However, what's the proper way to convert it, what format is the DateTime object in? What if I want to set the datetime? Would I have to convert it into hex format and assign it as a hex string?

There has to be a better and ideal way to extract modify the DateTime object.

Any ideas?

Thanks.

+2  A: 

A DateTime value in .NET can also be represented as a 64-bit value. The strange string format on DateTime fields on SharePoint list items is a variant of such a 64-bit value encoded as two 32-bit hex values. I have found no documentation from Microsoft on this format. But by trial and error I found the following conversion method:

string[] words = strVal.Split('|');
int high = int.Parse(words[0].Substring(2), System.Globalization.NumberStyles.HexNumber);
uint low = uint.Parse(words[1].Substring(2), System.Globalization.NumberStyles.HexNumber);
long ticks = high;
ticks = ticks << 32;
ticks += low;
DateTime t = new DateTime(ticks);
t = t.AddYears(1600);

where t holds the result.

Lars Fastrup
+3  A: 

I'm able to extract the date and time. That's fine.

So when you are modifying the DateTime of a ListItem, you just simply assign it as a DateTime format and it will interpret it correctly; no need to generate the hex that it returns.

LB