SQL 2008 Converting DateTime to ShortDate in SQL

In SQL, if we need to group by data and the database keep the data in datetime format, we will end up with more data as it will consider time in the date as well. So to format the datetime into date, we can use ShortDate by converting the date using various code (101, 112, …. all can be found here

To get today’s date in YYYYMMDD format:
SELECT CONVERT(CHAR(8), GETDATE(), 112)

To get today’s date in mm/dd/yyyy:
CONVERT(VARCHAR(10), GETDATE(), 101)

Advertisements
By simplemsexchange Posted in SQL 2008

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s