I have an SQL statement
SELECT NO, MEMBID, DATEFROM, DATETO from Member where MEMBID ='xxyy'
I get a return where the dates are in DateTime format. I only want them to be in Date format.
I have tried:-
SELECT NO, MEMBID, CONVERT(DATEFROM, GETDATE()), DATETO from Member where MEMBID ='xxyy'
SELECT NO, MEMBID, CAST(DATEFROM as DATE()), DATETO from Member where MEMBID ='xxyy'
these don't seem to be working.
I need to convert inside the SQL Statement itself. Been looking around on Google but can't seem to find anything. Any insights?
EDIT :- What finally worked for me is the following conversion technique.
CONVERT(VARCHAR(10), DATEFROM, 101)
这是一个将日期时间转换为日期的查询。
select cast('2014-06-04 00:00:00.000' as date)
There is no format in a DateTime
or Date
object. That only comes with the display of the data.
You were very close with the Convert, but needed just the output format .
CONVERT(VARCHAR(10), DATEFROM, 101)
This will output the DATEFROM
column as mm/dd/yyyy
This should work
SELECT NO, MEMBID, CAST(DATEFROM AS DATE), DATETO from Member where MEMBID ='xxyy'
for SQL SERVER 2012
it should be
SELECT NO, MEMBID, CONVERT(date, DATEFROM), DATETO from Member where MEMBID ='xxyy'
http://sqlfiddle.com/#!6/287dd/6 example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.