An issue with the SQlite database "The string was not recognized as a valid DateTime"

Source: Internet
Author: User
Tags iso 8601 sqlite sqlite database string format

Exception Details: System.FormatException: The string is not recognized as a valid DateTime.

Solution:

Convert a type when the date is saved to the SQLite database, for example: string _now = System.DateTime.Now.ToString ("s");

In other words. The ToString () method solves the problem of a date reading error by adding an S.

Simple code example:

String _indate = request["Indate"]; The date entered is as follows: 2009-2-21
DateTime _intime = Convert.todatetime (_indate);

The following is the SAVE data SQL statement

Insert into table (indate) VALUES (' "+ _intime.tostring (" s ") +" '); convert here

Because of the description of ISO 8601: (http://msdn.microsoft.com/zh-cn/library/ms187819.aspx)

Gives an example of a string:
* 2004-05-23T14:25:10
* 2004-05-23T14:25:10.487

So SQLite saves the date to be converted to ISO 8601 standard string format

Use date. ToString ("s"); This method is converted to the ISO 8601 standard string format.

An issue with the SQlite database "The string was not recognized as a valid DateTime"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.