• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

MySQL Command: STR_TO_DATE()

December 20, 2023

MySQL Command: STR_TO_DATE()

MySQL is a popular open-source relational database management system that is widely used for storing and managing data. One of the essential functions provided by MySQL is the STR_TO_DATE() command. This command allows users to convert a string representation of a date into a MySQL date format.

Understanding the STR_TO_DATE() Command

The STR_TO_DATE() command is used to convert a string into a date format that MySQL can recognize and manipulate. It takes two arguments: the string to be converted and the format specifier that defines the expected format of the string.

For example, suppose we have a string “2022-01-01” that we want to convert into a date format. We can use the STR_TO_DATE() command as follows:

SELECT STR_TO_DATE('2022-01-01', '%Y-%m-%d');

The format specifier ‘%Y-%m-%d’ indicates that the string should be in the format of “year-month-day”. The STR_TO_DATE() command will parse the string and return a date value that can be used in MySQL queries.

Common Format Specifiers

MySQL provides a wide range of format specifiers that can be used with the STR_TO_DATE() command to handle different date formats. Here are some commonly used format specifiers:

  • %Y: Four-digit year
  • %y: Two-digit year
  • %m: Month (01-12)
  • %d: Day of the month (01-31)
  • %H: Hour (00-23)
  • %i: Minutes (00-59)
  • %s: Seconds (00-59)

By combining these format specifiers, you can handle various date formats and convert them into MySQL date values using the STR_TO_DATE() command.

Example Usage

Let’s consider an example where we have a table named “orders” with a column named “order_date” that stores dates in the format “dd-mm-yyyy”. To query orders within a specific date range, we need to convert the string representation of the dates into MySQL date values.

SELECT * FROM orders WHERE STR_TO_DATE(order_date, '%d-%m-%Y') BETWEEN '2022-01-01' AND '2022-01-31';

In this example, the STR_TO_DATE() command is used to convert the “order_date” column into a MySQL date value. The format specifier ‘%d-%m-%Y’ indicates that the string should be in the format of “day-month-year”. The converted date values are then compared with the specified date range using the BETWEEN operator.

Summary

The STR_TO_DATE() command in MySQL is a powerful tool for converting string representations of dates into MySQL date values. By using the appropriate format specifiers, you can handle various date formats and perform date-related operations in your MySQL queries.

If you are looking for reliable and high-performance VPS hosting solutions, consider Server.HK. With a wide range of plans and excellent customer support, Server.HK is a trusted provider in the industry.

Recent Posts

  • VPS Hosting vs Shared Hosting: Why the Upgrade Is Worth It for Asia-Facing Websites
  • Hong Kong VPS vs Google Cloud Asia: Which Delivers Better China Performance in 2026?
  • Why No-ICP-Filing Hong Kong Hosting Is the Smart Choice for Cross-Border E-Commerce
  • Hong Kong VPS vs AWS Hong Kong Region: Cost, Latency, and Control Compared
  • Data Privacy Laws in Hong Kong: What VPS Users Need to Know

Recent Comments

  1. linezolid cost oral on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  2. metoprolol generic on Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026
  3. levitra price on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  4. finasterid on Hong Kong VPS vs Singapore VPS: Which Is Better for Your Asia Business in 2026?
  5. doxycycline hyclate 100mg on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot