all groups > sql server misc > august 2004 >
You're in the

sql server misc

group:

Converting Date+Time to Date


Converting Date+Time to Date Maziar Aflatoun
8/21/2004 3:54:20 PM
sql server misc:
Hi everyone,

I have a database with a date field 'StartDate' as smalldatetime. I need to
grab the date part and not the time part.

Ex. 2004-08-01 00:00:00 all I need is the 2004-08-01

How do I do that using SQL (Convert or Cast?? )?

Also, is there another datatype I can define it as in the the database so
that it's only date not time and date like date in MySQL.

Thank you
Maz



Re: Converting Date+Time to Date Muzzy
8/31/2004 11:09:27 PM
Well, as i know there is only one date type in sql server - smalldatetime
If you want to extract just date you can use date to string conversion:

CONVER(CHAR(4),YEAR(dateField)) +'-'+ CONVER(CHAR(2),MONTH(dateField)) + '-'
+
CONVER(CHAR(2),DAY(dateField))

So you get the string '2004-08-01'

HIH,
Andrey aka Muzzy

[quoted text, click to view]

AddThis Social Bookmark Button