Home > Sql Server > Get Only Date from Datetime in Sql

Get Only Date from Datetime in Sql


Sometimes we need to have only date from datetime field in sql.

There are number of ways to accomplish that:

Suppose we take current date

select getdate()

now to take only date from current date excluding time, we do as follows in various ways:


select DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
select convert(varchar,getdate(),101)
select convert(char(8),getdate(),1)
select cast(cast(getdate() as int) as datetime)
select cast(convert(varchar,getdate(),110) as datetime)

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: