I am trying to get the date portion of a datetime field. I know I can get it with date_format, but that returns a string or "varchar" field. How can I convert the result to date and not as varchar?
This is my query returning the varchar:
(Select Date_Format(orders.date_purchased,'%m/%d/%Y')) As Date
I tried several combinations from this question, but could not make it to work:
Any help is appreciated.
解决方案
Try to cast it as a DATE
SELECT CAST(orders.date_purchased AS DATE) AS DATE_PURCHASED