Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include milliseconds in a DateTime user setting?

I have the following user setting defined in app.config:

<userSettings>
    <MyProject.Properties.Settings>
        <setting name="LastProcessedDate" serializeAs="String">
            <value>07/06/2010 13:05:10</value>
        </setting>
    </MyProject.Properties.Settings>
</userSettings>

Is there a way to specify that this setting should be serialized with the milliseconds - e.g. 07/06/2010 13:05:10.181 - so that I can accurately compare it to a SQL Server datetime field?

like image 805
MCS Avatar asked Dec 29 '22 11:12

MCS


2 Answers

Unfortunately, you can't save millisecond values in settings. Deep down in the System.Configuration.SettingsPropertyValue.ConvertObjectToString method the DateTime value is converted to a string using the TypeConverter.ConvertToInvariantString method which doesn't produce milliseconds.

If you really want that level of accuracy and you must save it in the user settings, you should use a different parameter type like string using a custom format that includes milliseconds. None of the standard time formats includes milliseconds.

like image 82
Panagiotis Kanavos Avatar answered Jan 15 '23 08:01

Panagiotis Kanavos


You could try storing it as an Int64, which would preserve the entire value of the DateTime without any formatting issues or loss of fidelity.

like image 31
codekaizen Avatar answered Jan 15 '23 07:01

codekaizen