Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql format timestamp dd/mm/yyyy

select to_char(date_col, 'DD/MM/YYYY') from table;
Comment

SQL query to convert DD/MM/YYYY to YYYY-MM-DD

SELECT CONVERT(varchar(10), CONVERT(date, '13/12/2016', 103), 120)
Comment

sql server date format dd/mm/yyyy

select convert(varchar, getdate(), 103);
	output: 30/12/2006 (dd/mm/yyyy)
    
-- Below more pattern: 
DATE ONLY FORMATS
select convert(varchar, getdate(), 1);
	output: 12/30/06 (mm/dd/yy)
select convert(varchar, getdate(), 2);	
	output: 06.12.30 (yy.mm.dd)
select convert(varchar, getdate(), 3);	
	output: 30/12/06 (dd/mm/yy)
select convert(varchar, getdate(), 4);	
	output: 30.12.06 (dd.mm.yy)	
select convert(varchar, getdate(), 5);
	output: 30-12-06 (dd-mm-yy)
select convert(varchar, getdate(), 6);	
	output: 30 Dec 06 (dd-Mon-yy)
select convert(varchar, getdate(), 7);	
	output: Dec 30, 06 (Mon dd, yy)
select convert(varchar, getdate(), 10);	
	output: 12-30-06 (mm-dd-yy)
select convert(varchar, getdate(), 11);
	output: 06/12/30 (yy/mm/dd)
select convert(varchar, getdate(), 12);	
	output: 061230 (yymmdd)
select convert(varchar, getdate(), 23);
	output: 2006-12-30 (yyyy-mm-dd)
select convert(varchar, getdate(), 101);
	output: 12/30/2006 (mm/dd/yyyy)
select convert(varchar, getdate(), 102);
	output: 2006.12.30 (yyyy.mm.dd)
select convert(varchar, getdate(), 103);
	output: 30/12/2006 (dd/mm/yyyy)
select convert(varchar, getdate(), 104);
	output: 30.12.2006 (dd.mm.yyyy)
select convert(varchar, getdate(), 105);
	output: 30-12-2006 (dd-mm-yyyy)
select convert(varchar, getdate(), 106);
	output: 30 Dec 2006 (dd Mon yyyy)
select convert(varchar, getdate(), 107);
	output: Dec 30, 2006 (Mon dd, yyyy)
select convert(varchar, getdate(), 110);	
	output: 12-30-2006 (mm-dd-yyyy)
select convert(varchar, getdate(), 111);	
	output: 2006/12/30 (yyyy/mm/dd)
select convert(varchar, getdate(), 112);
	output : 20061230 (yyyymmdd)
 	
TIME ONLY FORMATS
select convert(varchar, getdate(), 8);
	output: 00:38:54 (hh:mm:ss)
select convert(varchar, getdate(), 14);	
	output: 00:38:54:840 (hh:mm:ss:nnn)
select convert(varchar, getdate(), 24);	
	output: 00:38:54 (hh:mm:ss)
select convert(varchar, getdate(), 108);
	output: 00:38:54 (hh:mm:ss)
select convert(varchar, getdate(), 114);
	output: 00:38:54:840 (hh:mm:ss:nnn)
 	
DATE & TIME FORMATS
select convert(varchar, getdate(), 0);	
	output: Dec 30 2006 12:38AM (Mon dd yyyy hh:mm AM/PM)
select convert(varchar, getdate(), 9);
	output: Dec 30 2006 12:38:54:840AM (Mon dd yyyy hh:mm:ss:nnn AM/PM)
select convert(varchar, getdate(), 13);
	output: 30 Dec 2006 00:38:54:840AM (dd Mon yyyy hh:mm:ss:nnn AM/PM)
select convert(varchar, getdate(), 20);	
	output: 2006-12-30 00:38:54 (yyyy-mm-dd hh:mm:ss)
select convert(varchar, getdate(), 21);	
	output: 2006-12-30 00:38:54.840 (yyyy-mm-dd hh:mm:ss:nnn)
select convert(varchar, getdate(), 22);	
	output: 12/30/06 12:38:54 AM (mm/dd/yy hh:mm:ss AM/PM)
select convert(varchar, getdate(), 25);
	output: 2006-12-30 00:38:54.840 (yyyy-mm-dd hh:mm:ss:nnn)
select convert(varchar, getdate(), 100);
	output: Dec 30 2006 12:38AM (Mon dd yyyy hh:mm AM/PM)
select convert(varchar, getdate(), 109);	
	output: Dec 30 2006 12:38:54:840AM (Mon dd yyyy hh:mm:ss:nnn AM/PM)
select convert(varchar, getdate(), 113);
	output: 30 Dec 2006 00:38:54:840 (dd Mon yyyy hh:mm:ss:nnn)
select convert(varchar, getdate(), 120);
	output: 2006-12-30 00:38:54 (yyyy-mm-dd hh:mm:ss)
select convert(varchar, getdate(), 121);
	output: 2006-12-30 00:38:54.840 (yyyy-mm-dd hh:mm:ss:nnn)
select convert(varchar, getdate(), 126);
	output: 2006-12-30T00:38:54.840 (yyyy-mm-dd T hh:mm:ss:nnn)
select convert(varchar, getdate(), 127);	
	output: 2006-12-30T00:38:54.840 (yyyy-mm-dd T hh:mm:ss:nnn	)
 	
ISLAMIC CALENDAR DATES
select convert(nvarchar, getdate(), 130);
select convert(nvarchar, getdate(), 131);	
	output: 10/12/1427 12:38:54:840AM (dd mmm yyyy hh:mi:ss:nnn AM/PM)

select replace(convert(varchar, getdate(),101),'/','');
	output: 12302006 (mmddyyyy)
select replace(convert(varchar, getdate(),101),'/','') + replace(convert(varchar, getdate(),108),':','');	
	output: 12302006004426 (mmddyyyyhhmmss)
Comment

convert date to dd/mm/yyyy sql

select CONVERT(char(10), GetDate(),103)
/* 30/06/2021 */
Comment

SQL MM/dd/yyyy format

SELECT CONVERT(VARCHAR(11), GETDATE(), 101) AS [MM/DD/YYYY]
Comment

sql convert date to string yyyy-mm-dd

select CONVERT(char(10), GetDate(),126)
/* 2020-12-23 */
Comment

sql datetime format dd/mm/yyyy hh:mm am/pm

select FORMAT(@date,'MM/dd/yyyy hh:mm:s tt')
Comment

sql date format dd-mm-yyyy

SELECT FORMAT (getdate(), 'dd-MM-yy') as date
GO
Comment

convert dd/mm/yyyy to yyyy-mm-dd in sql server

set dateformat dmy;
select PersonalDetails_DOB
    ,convert(nvarchar(10), cast(PersonalDetails_DOB as datetime), 102) as ANSI_DOB
    ,convert(nvarchar(10), cast(PersonalDetails_DOB as datetime), 120) as ODBC_DOB
from Users;
Comment

sql datetime format dd/mm/yyyy hh:mm am/pm

select FORMAT(@date,'MM/dd/yyyy hh:mm:s tt')
Comment

sql convert format for MM/YYYY

DECLARE @myDate DATETIME = '2012-04-20 05:54:59'
SELECT FORMAT(@myDate, 'MM-yyyy')
Comment

PREVIOUS NEXT
Code Example
Sql :: concatenate two strings in sql 
Sql :: multiple count in sql 
Sql :: postgres concat 
Sql :: oracle nextval insert 
Sql :: plsql print 
Sql :: mysql cdn link 
Sql :: date format in postgresql 
Sql :: mysqldump --skip-lock-tables 
Sql :: sql update table set text to lowercase 
Sql :: install squirrel sql ubuntu 
Sql :: drop multiple columns in sql 
Sql :: list of all table names in sql server databse 
Sql :: oracle list datafiles 
Sql :: how to drop all tables in sql 
Sql :: create view in sql 
Sql :: install mysql 5.7 
Sql :: SQL DEFAULT Constraint With Alter Table 
Sql :: mysql union 
Sql :: update and replace mysql 
Sql :: check table exist postgresql 
Sql :: sum query in sql 
Sql :: psql select database 
Sql :: how to query date in sql server 
Sql :: show column names in sql table 
Sql :: version and edition of SQL Server Database Engine 
Sql :: launch sql script from docker in mysql 
Sql :: with postgres 
Sql :: ERROR 3948 (42000): Loading local data is disabled; this must be enabled on both the client and server sides 
Sql :: sql order by multiple columns 
Sql :: change password postgres pgserver 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =