milliseconds in Date


I have a class "date.cs" in which a property modifieddate is of the type DateTime.

In another class i am trying to read a datevalue from a datagridview which is populated from the database.

The database table has milliseconds in all its date columns.
When i try to read the date value from the datagridview and assign it to the modifieddate of the date.cs class the milliseconds value doesnt get assigned because of which i am facing errors.

How do i solve this problem of fetching the milliseconds value.

My piece of code

string modDate = Convert.Todatetime(dtv.rows[0].cells["datecolumn"].value.tostring("yyyy-MM-dd HH:mm:ss:fff"));

Datetime getDate = DateTime.ParseExact(modDate,"yyyy-MM-dd HH:mm:ss:fff",culture);
where culture :
CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentCulture;

and i assign this getDate to the modifieddate of the date.cs file.
At this time i am loosing the milliseconds part.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Not sure what is going wrong here, because i have no example of the contents of "datecolumn".   But the conversion from string to date to string to date looks fishy.  Have you tried simply? Which will try to convert the string in "datecolumn" to a date using the current culture.  

DateTime getDate = Convert.ToDateTime(dtv.rows[0].cells["datecolumn"]);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mjmarlow is right, there are a lot of conversions going on here, first you are doing datetime to string from the dataview, then that back to datetime using Convert.ToDateTime, then back to a string into modDate, then back to a datetime in getDate using ParseExact. Apart from anything else, this will stink for performance. Is there a reason you need to do it like this?

However, are you saying that getDate has the right datetime, including milliseconds and that you are then losing the milliseconds when you do FileInfo finf = new FileInfo("date.cs"); finf.ModifiedDate = getDate;? Does getDate definitely have the right milliseconds (you have checked them using the debugger)?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.