From edf07b36d31ebaf67fbc34276718a68abb2b1f61 Mon Sep 17 00:00:00 2001 From: Ieswaria Date: Thu, 3 Jul 2025 15:07:43 +0300 Subject: [PATCH 1/3] Create using_convert_function_sql_server --- .../using_convert_function_sql_server | 1 + 1 file changed, 1 insertion(+) create mode 100644 sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server diff --git a/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server @@ -0,0 +1 @@ + From 48735a2d24bf4fab17ae3e5622890922afbb498c Mon Sep 17 00:00:00 2001 From: Ieswaria Date: Thu, 3 Jul 2025 15:09:23 +0300 Subject: [PATCH 2/3] Add files via upload The code files for SQL 455: Convert Date format into DD/MM/YYYY format in SQL --- .../sample_table_creation.sql | 4 ++++ .../using_convert_function_sql_server.sql | 6 ++++++ .../using_date_format_function_mysql.sql | 6 ++++++ .../using_format_function_sql_server.sql | 6 ++++++ .../using_lpad_and_extract_function_postgresql.sql | 6 ++++++ .../using_lpad_function_mysql.sql | 6 ++++++ .../using_to_char_function_postgresql.sql | 6 ++++++ 7 files changed, 40 insertions(+) create mode 100644 sql-queries-dates/convert_date_into_custom_format_in_SQL/sample_table_creation.sql create mode 100644 sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server.sql create mode 100644 sql-queries-dates/convert_date_into_custom_format_in_SQL/using_date_format_function_mysql.sql create mode 100644 sql-queries-dates/convert_date_into_custom_format_in_SQL/using_format_function_sql_server.sql create mode 100644 sql-queries-dates/convert_date_into_custom_format_in_SQL/using_lpad_and_extract_function_postgresql.sql create mode 100644 sql-queries-dates/convert_date_into_custom_format_in_SQL/using_lpad_function_mysql.sql create mode 100644 sql-queries-dates/convert_date_into_custom_format_in_SQL/using_to_char_function_postgresql.sql diff --git a/sql-queries-dates/convert_date_into_custom_format_in_SQL/sample_table_creation.sql b/sql-queries-dates/convert_date_into_custom_format_in_SQL/sample_table_creation.sql new file mode 100644 index 00000000..8b6ab2d4 --- /dev/null +++ b/sql-queries-dates/convert_date_into_custom_format_in_SQL/sample_table_creation.sql @@ -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'); \ No newline at end of file diff --git a/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server.sql b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server.sql new file mode 100644 index 00000000..ef445cb3 --- /dev/null +++ b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server.sql @@ -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; \ No newline at end of file diff --git a/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_date_format_function_mysql.sql b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_date_format_function_mysql.sql new file mode 100644 index 00000000..95904c3f --- /dev/null +++ b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_date_format_function_mysql.sql @@ -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; \ No newline at end of file diff --git a/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_format_function_sql_server.sql b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_format_function_sql_server.sql new file mode 100644 index 00000000..a8a893a1 --- /dev/null +++ b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_format_function_sql_server.sql @@ -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; \ No newline at end of file diff --git a/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_lpad_and_extract_function_postgresql.sql b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_lpad_and_extract_function_postgresql.sql new file mode 100644 index 00000000..5de78c78 --- /dev/null +++ b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_lpad_and_extract_function_postgresql.sql @@ -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 \ No newline at end of file diff --git a/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_lpad_function_mysql.sql b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_lpad_function_mysql.sql new file mode 100644 index 00000000..29f2873b --- /dev/null +++ b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_lpad_function_mysql.sql @@ -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; \ No newline at end of file diff --git a/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_to_char_function_postgresql.sql b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_to_char_function_postgresql.sql new file mode 100644 index 00000000..ea82c84d --- /dev/null +++ b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_to_char_function_postgresql.sql @@ -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; \ No newline at end of file From 341859d3f9efac026ac230e8e3915556c96c8c60 Mon Sep 17 00:00:00 2001 From: Ieswaria Date: Thu, 3 Jul 2025 15:11:20 +0300 Subject: [PATCH 3/3] Delete sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server --- .../using_convert_function_sql_server | 1 - 1 file changed, 1 deletion(-) delete mode 100644 sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server diff --git a/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server b/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server deleted file mode 100644 index 8b137891..00000000 --- a/sql-queries-dates/convert_date_into_custom_format_in_SQL/using_convert_function_sql_server +++ /dev/null @@ -1 +0,0 @@ -