tags:

views:

783

answers:

4

Does anyone know how to convert these string hex values back into DateTime values?

Property my_DateProperty (System.String) = 0x01c9874e|0x98f28800

//l_item is SPListItem          
Hashtable l_properties = l_item.Properties;
if (l_properties != null)
{
    object l_value = null;
    foreach (string l_key in l_properties.Keys)
    {
        l_value = l_properties[l_key];
        Splogger.log("Property " + l_key + " (" + l_value.GetType().ToString() + ") = " + l_value.ToString());
    }
}
A: 

Could be you that the datetime is being converted into an "invariant" date by the ToString. See this.

Nat
+4  A: 

I discovered recently that this seems to occur only on Office 2007 documents (for other file types, the value is a standard string format for a date). The answer is that the hexadecimal value represents the number of ticks since the 1/1/1600. Here is a conversion that worked for me:

Dim dateVal as DateTime = New DateTime(Long.Parse(dateText.Replace("0x", "").Replace("|", ""), System.Globalization.NumberStyles.HexNumber)).AddYears(1600)

A: 

John M is absolutely right. I wanted to add that this format is used in the eventhandler's Afterproperties

Miro
A: 

Thank You John!! I was struggling with this. Your answer resolved my problem. I really didn't know this fact that nly on Office 2007 documents (for other file types, the value is a standard string format for a date). The answer is that the hexadecimal value represents the number of ticks since the 1/1/1600.

Thanks a ton Khushi

Khushi