SQLUSA.com
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format

How to sql format datetime without century?

Execute the following Microsoft SQL Server T-SQL example script to demonstrate sql datetime to text conversion.

The following conversion options are available for sql datetime format without century (YY format). Note that some conversions do include century. They are listed for completeness of the 0 - 25 option range. Adding 100 to the style number will result in the century format - YYYY or CCYY.

-- SQL convert datetime to text    

-- SQL convert datetime to varchar    

SELECT TextDate = convert(CHAR,getdate(), 0) --mon dd yyyy hh:mmAM (or PM) 

-- Feb 15 2019  5:41PM          

SELECT TextDate = convert(CHAR,getdate(), 1) --mm/dd/yy 

-- 02/15/19                     

SELECT TextDate = convert(CHAR,getdate(), 2) --yy.mm.dd 

SELECT TextDate = convert(CHAR,getdate(), 3) --dd/mm/yy 

SELECT TextDate = convert(CHAR,getdate(), 4) --dd.mm.yy 

SELECT TextDate = convert(CHAR,getdate(), 5) --dd-mm-yy 

SELECT TextDate = convert(CHAR,getdate(), 6) --dd mon yy 

SELECT TextDate = convert(CHAR,getdate(), 7) --mon dd, yy 

SELECT TextDate = convert(CHAR,getdate(), 8) --hh:mm:ss 

SELECT TextDate = convert(CHAR,getdate(), 9) --mon dd yy hh:mm:ss:mmmAM (or PM) 

SELECT TextDate = convert(CHAR,getdate(),10) --mm-dd-yy 

SELECT TextDate = convert(CHAR,getdate(),11) --yy/mm/dd 

SELECT TextDate = convert(CHAR,getdate(),12) --yymmdd 

SELECT TextDate = convert(CHAR,getdate(),13) --dd mon yyyy hh:mm:ss:mmm 

SELECT TextDate = convert(CHAR,getdate(),14) --hh:mm:ss:mmm(24h) 

SELECT TextDate = convert(CHAR,getdate(),20) --yyyy-mm-dd hh:mm:ss(24h) 

SELECT TextDate = convert(CHAR,getdate(),21) --yyyy-mm-dd hh:mm:ss.mmm 

SELECT TextDate = convert(CHAR,getdate(),22) --mm/dd/yy hh:mm:ss AM (or PM)

SELECT TextDate = convert(CHAR,getdate(),23) --yyyy-mm-dd

SELECT TextDate = convert(CHAR,getdate(),24) --hh:mm:ss

SELECT TextDate = convert(CHAR,getdate(),25) --yyyy-mm-dd hh:mm:ss.mmm 

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Microsoft SQL Server 2000 Training Videos at www.sqlusa.com.

FREE SQL & Business Intelligence / OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011
Invest in Your SUCCESS!

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts


Copyright 2005-2011, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.