Monday, January 20, 2025
HomeProgrammingChange Date Format(DD/MM/YYYY) in SQL SELECT ...

Change Date Format(DD/MM/YYYY) in SQL SELECT …

To change the date format in an SQL SELECT statement to DD/MM/YYYY, you can use the DATE_FORMAT function in MySQL or the equivalent for other databases.

Here’s an example in MySQL:

SELECT DATE_FORMAT(your_date_column, '%d/%m/%Y') AS formatted_date
FROM your_table;

Explanation:

  • %d: Day of the month (two digits, zero-padded)
  • %m: Month (two digits, zero-padded)
  • %Y: Year (four digits)
See also  How to Print in Java

For SQL Server, you can use FORMAT:

SELECT FORMAT(your_date_column, 'dd/MM/yyyy') AS formatted_date
FROM your_table;

In PostgreSQL, use TO_CHAR:

SELECT TO_CHAR(your_date_column, 'DD/MM/YYYY') AS formatted_date
FROM your_table;

Here’s an example in MySQL:

SELECT DATE_FORMAT(your_date_column, '%d/%m/%Y') AS formatted_date
FROM your_table;

Explanation:

  • %d: Day of the month (two digits, zero-padded)
  • %m: Month (two digits, zero-padded)
  • %Y: Year (four digits)
See also  API Development in Java

For SQL Server, you can use FORMAT:

SELECT FORMAT(your_date_column, 'dd/MM/yyyy') AS formatted_date
FROM your_table;
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x