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