locked
converting to date is not getting 12:00:00.000 RRS feed

  • Question

  • User-1738998028 posted

    I have this format -

     string nCout = Convert.ToDateTime(txtdepart.Text).ToString("yyyy-MM-dd 12:00:00.0000");
                DateTime nCoutDate = DateTime.ParseExact(nCout, "yyyy-MM-dd 12:00:00.0000", CultureInfo.InvariantCulture);

    and save in the nCoutDate in database, in the column it shown  "2015-11-19 00:00:00.000"  - but i need like this  "2015-11-19 12:00:00.000"

    can you advice

    Monday, November 16, 2015 8:37 AM

Answers

  • User-1738998028 posted



                string nCout = Convert.ToDateTime(txtdepart.Text).ToString("yyyy-MM-dd 12:00:00.0000");
                DateTime nCoutDate = Convert.ToDateTime(Convert.ToDateTime(nCout).ToString("yyyy-MM-dd 12:00:00.0000"));

    That solved anyway

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 16, 2015 9:12 AM

All replies

  • User-1738998028 posted



                string nCout = Convert.ToDateTime(txtdepart.Text).ToString("yyyy-MM-dd 12:00:00.0000");
                DateTime nCoutDate = Convert.ToDateTime(Convert.ToDateTime(nCout).ToString("yyyy-MM-dd 12:00:00.0000"));

    That solved anyway

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 16, 2015 9:12 AM
  • User61956409 posted

    Hi supermannum1,

    Firstly, I’m glad hear that you resolve the problem by yourself. And thanks for sharing your solution.

    Secondly, please check the "hh" custom format specifier and the "HH" custom format specifier sections to specify hour format.

    https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx#Anchor_20

    Best Regards,

    Fei Han

    Tuesday, November 17, 2015 2:53 AM