SQL converts datetime to a string and truncates a string.

Source: Internet
Author: User

SQL converts datetime to a string and truncates the string 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 'converted format and truncated time' from dbo. tb_sell_resources, dbo. tb_sell_selldetails where sr_id = ss_rsid and ss_qdstate <> 1 order by ss_updatetime SQL string truncation function: SUBSTRING (name, start, end) name: string format field name start: specify the start position (start value is 1) end: capture the end position of the string. in SQL, CONVERT the Datetime format to the string format: 2000-01-01 01:01:01 (Datetime) CONVERT (CHAR (19), CURRENT_TIMESTAMP, 120) CURRENT_TIMESTAMP: the current time (you can enter the field name in Datetime format, for example, ss_updatetime). Other parameters (CHAR (19), 120, etc.) do not need to be modified) changed to 01:01:01 (string format)
 

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.