locked
DateTime format in Sqlite RRS feed

  • Question

  • User335593 posted

    I have db with DateTime fields, in android app, I can only work with them if I change storeDateTimeAsTicks to false, but then I get them in string format("2019-08-10T21:58:13.000"). How do I convert it to DateTime and back to string, to change and return to db?

    Wednesday, August 14, 2019 11:07 PM

Answers

  • User382871 posted

    How do I convert it to DateTime and back to string Convert string type to DateTime: string time_string = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss tt"); DateTime date = Convert.ToDateTime(time_string); Convert Datetime type to string: string time = oDate.ToString("yyyy/MM/dd hh:mm:ss tt");

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, August 15, 2019 2:29 AM
  • User382871 posted

    @Cheeger Change the format as follows: string time = date.ToString("yyyy-MM-dd'T'hh:mm:ss.fff");

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, August 15, 2019 7:40 AM

All replies

  • User382871 posted

    How do I convert it to DateTime and back to string Convert string type to DateTime: string time_string = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss tt"); DateTime date = Convert.ToDateTime(time_string); Convert Datetime type to string: string time = oDate.ToString("yyyy/MM/dd hh:mm:ss tt");

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, August 15, 2019 2:29 AM
  • User335593 posted

    @Jarvan said:

    How do I convert it to DateTime and back to string Convert string type to DateTime: string time_string = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss tt"); DateTime date = Convert.ToDateTime(time_string); Convert Datetime type to string: string time = oDate.ToString("yyyy/MM/dd hh:mm:ss tt");

    It works, but Datetime after converting to string is displayed in SQLite Expert as: 1899-12-30 00:00:00.000.

    Thursday, August 15, 2019 6:59 AM
  • User382871 posted

    This value seems to be what results if there is a date that is deleted.

    Thursday, August 15, 2019 7:11 AM
  • User335593 posted

    @Jarvan said: This value seems to be what results if there is a date that is deleted.

    Date is not deleted, just SQLite Expert does not understand this format. This date returns to app as: "2019.08.10 09:33:04 AM" possible somehow turn it into: "2019-08-10T09:33:04.000"?

    Thursday, August 15, 2019 7:21 AM
  • User382871 posted

    @Cheeger Change the format as follows: string time = date.ToString("yyyy-MM-dd'T'hh:mm:ss.fff");

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, August 15, 2019 7:40 AM