sql怎麼取時間欄位的年月日的值
sql取時間欄位中年月日的值的步驟如下:
我們需要準備的材料分別是:電腦、sql查詢器。
1、首先,開啟sql查詢器,連線上相應的sql表。
2、點選“查詢”按鈕,輸入:SELECT date_format(add_time, ‘%Y’) as year, date_format(add_time, ‘%m’) as month, date_format(add_time, ‘%d’) as day FROM test;。
3、點選“執行”按鈕,時間欄位的年月日就被取出了。
select to_char(時間欄位,‘yyyy-mm-dd’) from 表名;
這樣就取出時間欄位中的年月日 ,格式為 2010-08-19
sqlserver裡有內建函式
select DATENAME(year,getdate()) //取年(返回字串)
select DATENAME(month,getdate()) //取月(返回字串)
select DATENAME(day,getdate()) //取日(返回字串)
select DATEPART(year,getdate()) //取年(返回整數)
select DATEPART(month,getdate()) //取月(返回整數)
select DATEPART(day,getdate()) //取日(返回整數)
<%=year(rs(‘’日期‘’))%>-<%=Month(rs(‘’日期‘’))%>-<%=day(rs(‘’日期‘’))%>=年-月-日
非常簡單:
select convert(char(10),jf_date,120) from 表名
OK!