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

December 20, 2023

MySQL Command: SUBDATE()

MySQL is a popular open-source relational database management system that is widely used for various web applications. It offers a wide range of functions and commands to manipulate and retrieve data efficiently. One such useful command is SUBDATE(), which allows you to subtract a specified time interval from a given date or datetime value.

Syntax

The syntax for the SUBDATE() command is as follows:

SUBDATE(date, INTERVAL expr unit)

Here, date is the date or datetime value from which you want to subtract the time interval. expr represents the number of units you want to subtract, and unit specifies the unit of time, such as day, month, year, hour, minute, or second.

Examples

Let’s explore some examples to understand how the SUBDATE() command works:

Example 1: Subtracting Days

SELECT SUBDATE('2022-01-15', INTERVAL 7 DAY);

This query will subtract 7 days from the given date ‘2022-01-15’ and return the result as ‘2022-01-08’.

Example 2: Subtracting Months

SELECT SUBDATE('2022-01-15', INTERVAL 3 MONTH);

In this example, the command will subtract 3 months from the date ‘2022-01-15’ and yield ‘2021-10-15’ as the output.

Example 3: Subtracting Hours

SELECT SUBDATE('2022-01-15 10:30:00', INTERVAL 2 HOUR);

Here, the command will subtract 2 hours from the datetime value ‘2022-01-15 10:30:00’ and return ‘2022-01-15 08:30:00’.

Usage and Benefits

The SUBDATE() command can be beneficial in various scenarios. Some common use cases include:

  • Calculating the expiration date of a subscription by subtracting the subscription duration from the start date.
  • Calculating the age of a person by subtracting their birthdate from the current date.
  • Generating reports based on a specific time range by subtracting a certain number of days, months, or years from the current date.

By utilizing the SUBDATE() command, you can perform these calculations directly within your MySQL queries, saving time and effort.

Summary

The SUBDATE() command in MySQL is a powerful tool for subtracting a specified time interval from a given date or datetime value. It allows you to perform various calculations and manipulations within your database queries. Whether you need to calculate expiration dates, determine ages, or generate reports based on specific time ranges, the SUBDATE() command can simplify these tasks. To learn more about VPS hosting solutions and how they can benefit your business, visit Server.HK.

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