Discussion on the DateTime type

Source: Internet
Author: User

The DateTime type exists in SQL and C #. In the interaction with the database, this data type is also the most troublesome,

However, I believe that after my explanation, you will be familiar with this data type. Now let's play with DateTime:
First, we will talk about DateTime in SQL. we can add a DateTime type record to the database using SQL statements in two ways: hard writing and date functions in SQL.
1. hard writing is not commonly used, but you will learn something through this writing method: insert into mermerinfo (birthday) values () The statement above inserts a birthday record into the user table, here, we enclose the date in single quotes. Some people may say that it is okay to exclude it. That's right, but it is okay to write the following year, month, and day without parentheses, but you want to set the birthday: 12:16:31, when accurate to seconds, errors will occur without parentheses. To facilitate memory and prevent errors, we recommend that you add parentheses when writing hard.
2. There are several date functions in SQL using the date functions in SQL. I will explain them in detail in the next article. The most common date function is GetDate (). The function is used to call the current time. The format is similar to 14:51:32. 107 the last three digits are in Greenwich Mean Time format, so you don't need to worry about it. The method of the subfunction used in SQL statements is update dbo. customerInfo set birthday = GetDate () where customerInfoId = 13
Next, let's take a look at the DateTime in C #. DateTime in C # is an object, and it has many attributes and methods, this is something that needs to be explained in a specific article. Now we only need to know That DateTime has these three methods: ToString (), tow.datestring (), and tow.timestring (). These three methods are the most common things in DateTime, And the things obtained by ToString () are similar to 14:51:32; tow.datestring () is similar to; and tow.timestring () is similar to 14:51:32.
When we connect to the database and use the C # statement to pass the SQL statement to the SQL statement, we should pay attention to a small detail. This is also a small error I have made, I was depressed for half an afternoon,
Note: In the third row of sqlStr above, there is no single quotation mark for filling the position of birthday! Pay attention to this.

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.