Reputation: 14112
I'm getting a hex string when converting a SPListItem's date.
eg. "0x01c9d2be|0x809a8800"
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.
Upvotes: 4
Views: 1366
Reputation: 11
Another solution can be found here. It has something to do how Office 2007 stores dates.. SPListItem.Properties DateTime Fields are in weird Hex format
Upvotes: 1
Reputation: 14112
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.
Upvotes: 3
Reputation: 5506
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.
Upvotes: 2