SQL:从表中获取日期 [英] SQL: Get date from table

查看:53
本文介绍了SQL:从表中获取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列存储日期时间,例如2011-01-01 01:01:01.

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

我需要获取日期列表:

2011-01-01
2011-02-01

有什么办法可以在表中从日期时间列出下来的日期?

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

推荐答案

如果该列确实是日期时间,则只需使用date()函数:

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

select date(column)
from table t;

实际上,如果该列是字符串(假定其为YYYY-MM-DD格式),这也适用.

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;

这篇关于SQL:从表中获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆