Get Sql Datetime Column without Timestamp

Sometimes, you would want to obtain only the ‘date’ part of a SQL datetime timestamp column.

Normally, your datetime column will hold dates in the following format.

2012-04-17 20:18:02.687

You can do the following to remove its time section

SELECT CAST(YourColumnName AS varchar(12)) AS DesiredColumnName from YourTableName where YourColumnName > ’2012/05/01′

This will result in the following

Feb 21 2002

It renders date in a more readable format, great when presenting dates on your website using either GridView or Repeater control.

Hope this is helpful.

Advertisements

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