Home > BI, Code, Tips > Quick Reference to SQL Server Date Formats

Quick Reference to SQL Server Date Formats

Just stumbled upon this site that has a great list of common SQL Server date formats. It’s never easy in SQL to format dates, but with this list, it should be simple.

This also includes 3 simple ways to get JUST the date portion of a datetime field. When you’re just starting with SQL, this is about the most common question.


CAST(CONVERT(VARCHAR(10), @pInputDate, 111) AS DATETIME)


CAST(CAST(YEAR(@pInputDate) AS VARCHAR(4)) + '/' +
CAST(MONTH(@pInputDate) AS VARCHAR(2)) + '/' +
CAST(DAY(@pInputDate) AS VARCHAR(2)) AS DATETIME)


CAST(FLOOR(CAST(@pInputDate AS DECIMAL(12, 5))) AS DATETIME)

http://www.sql-server-helper.com/tips/date-formats.aspx

VN:F [1.9.6_1107]

Rating: 0.0/5 (0 votes cast)
VN:F [1.9.6_1107]
Rating: 0 (from 0 votes)
Categories: BI, Code, Tips Tags:
  1. No comments yet.
  1. No trackbacks yet.