Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Select Date in SQL

Select Date in SQL

? SELECT DATE() in SQL

The DATE() function extracts the date part (year-month-day) from a datetime or timestamp value, effectively removing the time portion.


Usage

SELECT DATE(datetime_column) FROM table_name;
  • It returns only the date (YYYY-MM-DD).

  • Supported in MySQL and some other SQL dialects.

  • In SQL Server, use CAST(datetime_column AS DATE) or CONVERT(DATE, datetime_column) instead.

  • In PostgreSQL, use ::date cast or DATE() function.


? Examples:

MySQL:

SELECT DATE(order_date) AS order_only_dateFROM orders;

SQL Server equivalent:

SELECT CAST(order_date AS DATE) AS order_only_dateFROM orders;

PostgreSQL equivalent:

SELECT order_date::date AS order_only_dateFROM orders;

Use Case

If a column stores date and time (like 2025-06-06 14:30:00), but you want just 2025-06-06, use DATE().


Would you like to see how to filter by date using DATE()?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql