每个数据库,不同的日期格式化:
1、mysql
2、sqlserver
使用Convert()函数: select convert(char(10),GetDate(),120) as Date
第3个参数就是用来设置日期类型数据的显示样式的,下面介绍几种样式的参数:
3、vba
Sub 测试() Dim Con As Object Set Con = CreateObject("ADODB.Connection") Con.Open "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=no;imex=1';Data Source=" & ActiveWorkbook.FullName Dim sql As String, sql_1 As String, t As String, rs As Object Dim monthArr As New Collection, i, n, s_month t = "Sheet10" & "$" sql = " format(f1,'yyyy-mm-dd') as 结果1, left(f1,10) as 结果2, datediff('d',f1,now) as 结果3 " sql = " SELECT " & sql & " from [" & t & "] " Set rs = Con.Execute(sql) For i = To rs.fields.Count -
Cells(, i + ) = rs.fields(i).Name
Next Cells(, ).CopyFromRecordset rs rs.Close: Set rs = Nothing Con.Close: Set Con = Nothing End Sub