SQL converts datetime to a string and truncates a string.

Source: Internet
Author: User
Selectsr_childas

Select sr_child

Select sr_child as 'child name', sr_parents as 'parent name', ss_updatetime as 'allocation time', left (ss_updatetime, CHARINDEX ('', ss_updatetime)-1 ), SUBSTRING (CONVERT (CHAR (19), ss_updatetime, 120),) as 'time after format conversion and truncation 'from dbo. tb_sell_resources, dbo. tb_sell_selldetails where sr_id = ss_rsid and ss_qdstate <> 1 order by ss_updatetime

String truncation function in SQL: SUBSTRING (name, start, end)

Name: field name in string format

Start: Specifies the start position (the start value is 1)

End: Specifies the position at which the string ends.

In SQL, The Datetime format is converted to the string format: 2000-01-01 01:01:01 (Datetime) CONVERT (CHAR (19), CURRENT_TIMESTAMP, 120)

CURRENT_TIMESTAMP: Current Time (Field Names in Datetime format can be written here, for example, ss_updatetime)

Other parameters (CHAR (19), 120, etc.) do not need to be modified

After use, 01:01:01 (Datetime) is changed to 01:01:01 (string format)

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.