Use MySQL built-in functions to convert strings to dates

Source: Internet
Author: User

MySQL built-in functions are very important functions. We can use MySQL built-in functions to convert strings to dates. The following describes this method for your reference.

Use str_to_date) in mysql to convert a string to a date.

MySQL built-in function instance:

The separators are the same, and the year, month, and day must be the same.

 
 
  1. select str_to_date('02/25/1998 12:00:34 AM','%m/%d/%y %h:%i:%s %s') as column_name from table_name;  
  2.  
  3. str_to_date('08/09/2008', '%m/%d/%Y'); -- 2008-08-09  
  4.  
  5. str_to_date('08/09/08' , '%m/%d/%y'); -- 2008-08-09  
  6.  
  7. str_to_date('08.09.2008', '%m.%d.%Y'); -- 2008-08-09  
  8.  
  9. str_to_date('08:09:30', '%h:%i:%s'); -- 08:09:30  
  10.  
  11. str_to_date('08.09.2008 08:09:30', '%m.%d.%Y %h:%i:%s'); -- 2008-08-09 08:09:30  
  12.  

Difference between NULL and MySQL NULL strings

In-depth study of MySQL result strings

MySQL string truncation Function Method

MySQL string segmentation implementation

MySQL replaces the specified field string in batches

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.