hello everyone in this tutorial
uh i'm going to show you how to return
the date part only from a
sql
server date time data type
let me explain what i mean
so
if i do new query
select
get date
and then run this query
as you can see i get
a datetime data type
which has
the date part
and the time part
what i want
is a way
to get only the date part
from a date time data type
so that's
what we want to do in this tutorial
if we take for example the adventure
works sample database let's expand this
go to tables
and look for the
person or employee
table
which is
this one
okay i'm looking for a
date time dated type
higher date is just date
no time with it
okay let's try another table
maybe product
okay maybe on the product table it has
this column cell start date
okay let me remove the extra
columns
just to make the query a little bit
simple
to manipulate
okay
so let's say we want to extract the date
part from this
column cell start date
so there are different ways to do this
one way is
to
use the
convert
function
so let's say convert to date
the column
cell
sorry not end date but rather
start date
let me remove this
so convert to date cell start date
as
for example
cell start date
one
let's run this
so as you can see sales start date one
has only the date part
so we use the convert
to date
and then the column name
another way to do this is to use the
cost
function
so the syntax is cast
column name
as
date
and then give it a name
as cell start date
two
so let's run this again
and as you can see
uh cell start date
two
also
contains the date part
of this datetime
column
so there you go these are two ways
to
extract
the date part
of the datetime data type in sql server
using the functions convert and cast
i hope this video has been helpful for
you and thank you for watching