Date Formatting In SQL

March 19, 2010    SQL

image

I got a request for a report the other day so I built this massive 90 line SQL statement to pull all the data requested. So I sent off a copy of the data report and the guy tells me that he needs the date formatted (YYYYMMDD) instead of (YYYY-MM-DD-HHMMSS) and then he was like is that going to be a problem and I was like ha not really. Give me a moment and I’ll send you a simple. Since I can’t remember the correct expression I did a quick Google search and came across this awesome page http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/ covering exactly what I was looking for.