Question

I have a column which stores datetime like 2011-01-01 01:01:01 .

I need to get list of date:

2011-01-01
2011-02-01

Is there any way I can list down date from datetime in a table?

No correct solution

OTHER TIPS

If the column is really a datetime, just use the date() function:

select date(column)
from table t;

Actually, this also works if the column is a string, assuming it is in YYYY-MM-DD format.

If you want a unique list of dates:

select distinct date(column)
from table t;
select substr(field,1,10)

For just a list of the dates.

SELECT DATE_FORMAT(field, '%Y-%m-%d')

SQL

select to_char(date_column,'YYYY-MM-DD') from table;

MySql

SELECT STR_TO_DATE(date_column,'%Y-%m-%d') from table;

You can use DATE_FORMAT().

Syntax:

SELECT DATE_FORMAT('2011-10-10 19:46:00', '%M %d, %Y');

Try this code

SELECT CONVERT(date,Column_Name) As Date FROM Table_Name

thank you for all answers.

what i really need is year. sorry for the misleading question.

the correct query for that is:

select distinct YEAR(created_on) as years from contacts

thank you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top