Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add files via upload
The code files for SQL 455: Convert Date format into DD/MM/YYYY format in SQL
  • Loading branch information
ieswaria authored Jul 3, 2025
commit 48735a2d24bf4fab17ae3e5622890922afbb498c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- A sample table creation
CREATE TABLE Payment ( id INT AUTO_INCREMENT PRIMARY KEY, customer_name VARCHAR(100), date_of_payment DATE );
-- Insertion of sample data
INSERT INTO Payment (customer_name, date_of_payment) VALUES ('Alice Johnson', '2025-06-01'), ('Bob Smith', '2025-06-15'), ('Charlie Lee', '2025-06-20'), ('Diana Patel', '2025-06-25');
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- A sample table creation
CREATE TABLE Payment ( id INT IDENTITY(1,1) PRIMARY KEY, customer_name VARCHAR(100), date_of_payment DATE );
-- Insertion of sample data
INSERT INTO Payment (customer_name, date_of_payment) VALUES ('Alice Johnson', '2025-06-01'), ('Bob Smith', '2025-06-15'), ('Charlie Lee', '2025-06-20'), ('Diana Patel', '2025-06-25');
-- Using CONVERT Function
SELECT id, customer_name, CONVERT(VARCHAR(100), date_of_payment, 103) AS formatted_date FROM Payment;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- A sample table creation
CREATE TABLE Payment ( id INT AUTO_INCREMENT PRIMARY KEY, customer_name VARCHAR(100), date_of_payment DATE );
-- Insertion of sample data
INSERT INTO Payment (customer_name, date_of_payment) VALUES ('Alice Johnson', '2025-06-01'), ('Bob Smith', '2025-06-15'), ('Charlie Lee', '2025-06-20'), ('Diana Patel', '2025-06-25');
-- Using DATE Function
SELECT id, customer_name, DATE_FORMAT(date_of_payment, '%d/%m/%Y') AS converted_date FROM Payment;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- A sample table creation
CREATE TABLE Payment ( id INT IDENTITY(1,1) PRIMARY KEY, customer_name VARCHAR(100), date_of_payment DATE );
-- Insertion of sample data
INSERT INTO Payment (customer_name, date_of_payment) VALUES ('Alice Johnson', '2025-06-01'), ('Bob Smith', '2025-06-15'), ('Charlie Lee', '2025-06-20'), ('Diana Patel', '2025-06-25');
-- Using FORMAT Function
SELECT id, customer_name, FORMAT(date_of_payment, 'dd/MM/yyyy') AS converted_date FROM Payment;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- A sample table creation
CREATE TABLE Payment ( id SERIAL PRIMARY KEY, customer_name VARCHAR(100), date_of_payment DATE );
-- Insertion of sample data
INSERT INTO Payment (customer_name, date_of_payment) VALUES ('Alice Johnson', '2025-06-01'), ('Bob Smith', '2025-06-15'), ('Charlie Lee', '2025-06-20'), ('Diana Patel', '2025-06-25');
-- Using LPAD and EXTRACT Function
SELECT id, customer_name, LPAD(EXTRACT(DAY FROM date_of_payment)::TEXT, 2, '0') || '/' || LPAD(EXTRACT(MONTH FROM date_of_payment)::TEXT, 2, '0') || '/' || EXTRACT(YEAR FROM date_of_payment)::TEXT AS converted_date FROM Payment
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- A sample table creation
CREATE TABLE Payment ( id INT AUTO_INCREMENT PRIMARY KEY, customer_name VARCHAR(100), date_of_payment DATE );
-- Insertion of sample data
INSERT INTO Payment (customer_name, date_of_payment) VALUES ('Alice Johnson', '2025-06-01'), ('Bob Smith', '2025-06-15'), ('Charlie Lee', '2025-06-20'), ('Diana Patel', '2025-06-25');
-- Using LPAD Function
SELECT id, customer_name, CONCAT( LPAD(DAY(date_of_payment), 2, '0'), '/', LPAD(MONTH(date_of_payment), 2, '0'), '/', YEAR(date_of_payment) ) AS converted_date FROM Payment;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- A sample table creation
CREATE TABLE Payment ( id SERIAL PRIMARY KEY, customer_name VARCHAR(100), date_of_payment DATE );
-- Insertion of sample data
INSERT INTO Payment (customer_name, date_of_payment) VALUES ('Alice Johnson', '2025-06-01'), ('Bob Smith', '2025-06-15'), ('Charlie Lee', '2025-06-20'), ('Diana Patel', '2025-06-25');
-- Using TO_CHAR Function
SELECT id, customer_name, TO_CHAR(date_of_payment, 'DD/MM/YYYY') AS converted_date FROM Payment;