none
loosing milliseconds from datetime in qyery RRS feed

  • Question

  • Hi, i have a datetime column which has dates with milliseconds, but when i make a query and try to read that column i get the correct datetime but without dhe milliseconds.

    I use a conversion like this:  DateTime oColumn =DateTime.Parse(oRow["Start"].ToString());

    Is there anyway to get the milliseconds from the column.

    Thank you.

    • Moved by Bob Beauchemin Monday, October 11, 2010 11:47 AM Moved to a more relevent forum (From:.NET Framework inside SQL Server)
    Monday, October 11, 2010 10:47 AM

Answers

  • Hello,

    With .ToString() you get a string with the default formating for a date time, and that's without milliseconds.

    Why do you convert a datetime object first to string and then back to datetime? Use it as it is.


    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    • Proposed as answer by Olaf HelperMVP Wednesday, October 13, 2010 10:47 AM
    • Marked as answer by liurong luo Friday, October 15, 2010 4:49 AM
    Monday, October 11, 2010 10:59 AM
  • I solved it by converting this way  datetime x=(datetime)oRow["column"]

    Thanks

    • Marked as answer by liurong luo Friday, October 15, 2010 4:49 AM
    Wednesday, October 13, 2010 9:25 AM

All replies

  • Hello,

    With .ToString() you get a string with the default formating for a date time, and that's without milliseconds.

    Why do you convert a datetime object first to string and then back to datetime? Use it as it is.


    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    • Proposed as answer by Olaf HelperMVP Wednesday, October 13, 2010 10:47 AM
    • Marked as answer by liurong luo Friday, October 15, 2010 4:49 AM
    Monday, October 11, 2010 10:59 AM
  • Do you see milliseconds before conversion to string? I mean, do you see proper value inside of DataColumn after the value retrieved from the database? If yes, then you can provide mask for ToString method and get milliseconds inside of the string as well. If you do not see proper values, can you post the code/stored procedure that retrieves data from the database?
    Val Mazur (MVP) http://www.xporttools.net
    Tuesday, October 12, 2010 10:21 AM
    Moderator
  • I solved it by converting this way  datetime x=(datetime)oRow["column"]

    Thanks

    • Marked as answer by liurong luo Friday, October 15, 2010 4:49 AM
    Wednesday, October 13, 2010 9:25 AM