• 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: DATE_FORMAT()

December 20, 2023

MySQL Command: DATE_FORMAT()

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 DATE_FORMAT() command, which allows users to format date and time values in various ways. In this article, we will explore the DATE_FORMAT() command and its usage in MySQL.

Introduction to DATE_FORMAT()

The DATE_FORMAT() function in MySQL is used to format date and time values according to a specified format. It takes two arguments: the date or time value to be formatted and the format string that defines the desired output format.

The format string can include various format specifiers, such as %Y for the year, %m for the month, %d for the day, %H for the hour, %i for the minutes, %s for the seconds, and many more. By combining these specifiers, you can create custom date and time formats.

Usage Examples

Let’s look at some examples to understand how the DATE_FORMAT() command works:

SELECT DATE_FORMAT(NOW(), '%Y-%m-%d') AS formatted_date;

This query will return the current date in the format ‘YYYY-MM-DD’. For example, if the current date is January 15, 2022, the result will be ‘2022-01-15’.

SELECT DATE_FORMAT('2022-01-15', '%W, %M %e, %Y') AS formatted_date;

In this example, we are formatting a specific date (‘2022-01-15’) using the format string ‘%W, %M %e, %Y’. The result will be the full weekday name, followed by the full month name, the day of the month with a leading zero, and the four-digit year. For the given date, the result will be ‘Saturday, January 15, 2022’.

Custom Date and Time Formats

MySQL provides a wide range of format specifiers that can be used to create custom date and time formats. Here are some commonly used specifiers:

  • %Y: Four-digit year (e.g., 2022)
  • %y: Two-digit year (e.g., 22)
  • %m: Month with leading zero (e.g., 01 for January)
  • %c: Month without leading zero (e.g., 1 for January)
  • %d: Day of the month with leading zero (e.g., 01)
  • %e: Day of the month without leading zero (e.g., 1)
  • %H: Hour in 24-hour format with leading zero (e.g., 09)
  • %h: Hour in 12-hour format with leading zero (e.g., 09 or 12)
  • %i: Minutes with leading zero (e.g., 05)
  • %s: Seconds with leading zero (e.g., 02)

These are just a few examples, and there are many more format specifiers available in MySQL. You can combine them in any order and add additional characters or symbols to create the desired format.

Conclusion

The DATE_FORMAT() command in MySQL is a powerful tool for formatting date and time values according to specific requirements. By using the format specifiers provided by MySQL, you can create custom date and time formats that suit your needs. Whether you need to display dates in a specific format or perform calculations based on formatted dates, the DATE_FORMAT() command can help you achieve your goals.

Summary

In summary, the DATE_FORMAT() command in MySQL allows users to format date and time values according to a specified format. It takes a date or time value and a format string as arguments. The format string can include various format specifiers to create custom date and time formats. By using the DATE_FORMAT() command, you can easily format dates and times in MySQL to meet your specific requirements.

For more information about VPS hosting services, visit Server.HK.

Recent Posts

  • How to Configure Nginx Load Balancing on Hong Kong VPS for High-Traffic Sites (2026)
  • How to Migrate Your Website to a Hong Kong VPS: Zero-Downtime Transfer Guide (2026)
  • How to Set Up Redis on Hong Kong VPS: Caching, Queues, and Session Storage (2026)
  • How to Host a Python Flask or Django Application on Hong Kong VPS (2026)
  • How to Set Up WireGuard VPN on a Hong Kong VPS: Step-by-Step Guide 2026

Recent Comments

  1. vibramycin injection on How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  2. allopurinol for gout on CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  3. antibiotics online purchase on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)
  4. linezolid cost oral on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  5. metoprolol generic on Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 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