我试图转换并显示我的日期,就像从2017年6月4日到2017-06-04。这些是我的代码。我该怎么做?
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
conn.Open "Provider=SQLOLEDB.1;Data Source=PC01\SQLEXPRESS;Initial Catalog=TEST","admin","admin"
sql = "select SAS_DIRECTOR_APPOINTMENT.DATE_OF_APPOINTMENT from SAS_DIRECTOR_APPOINTMENT where SAS_DIRECTOR_APPOINTMENT.WIP_GUID='0000000003'"
rs.Open sql,conn
MsgBox rs.Fields(0)
答案 0 :(得分:1)
SAS_DIRECTOR_APPOINTMENT.DATE_OF_APPOINTMENT
列不属于appropriate DATE data type,请更改数据库的设计。Pd()
)只是因为你在你的代码中调用它而存在。答案 1 :(得分:0)
试试这个:
<![CDATA[<%
response.write YEAR(Date()) & _
"-" & Pd(Month(date()),2) & _
"-" & Pd(DAY(date()),2)
%>]]>
答案 2 :(得分:0)
根据OP,通过CONVERT()
使用undocumented argument 23函数解决了问题。
sql = "declare @datetemp as date;" & _
"set @datetemp = (select SAS_DIRECTOR_APPOINTMENT.DATE_OF_APPOINTMENT from SAS_DIRECTOR_APPOINTMENT where SAS_DIRECTOR_APPOINTMENT.WIP_GUID='0000000003');" & _
"SELECT CONVERT(NVARCHAR(10), @datetemp, 23), 23"