请问如何在Access里分隔开如下的数据,急!急!急!

terpitude2002 2004-08-08 08:50:01
数据库字段内容为2004-8-9 12:32:12,我想把2004-8-9分离出来.但是Access不支持split函数,请问怎么处理?
我曾经用过left(time,len(time)-9))来取,但是发现了问题.就是有的时间为:2004-8-9 0:00:12,就会出错.还要加判断,请问大家有什么好的办法?
...全文
430 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
openhouse 2004-08-09
  • 打赏
  • 举报
回复
是呀!用format就可以转换成yyyy-MM-dd的格式呀!
format(rq,"yyyy-MM-dd")
format(rq,"hh:mm:ss")
如:
dim strDate as string
strdate=format(rq.date,"yyyy-MM-dd")
zhangzhijian 2004-08-09
  • 打赏
  • 举报
回复
可以!
熊孩子开学喽 2004-08-09
  • 打赏
  • 举报
回复
access不支持,可VB支持啊,先将数据读出来再合并,再存放到数据库中(使用文本型字段)
talent303 2004-08-09
  • 打赏
  • 举报
回复
先格式化,,,,
format(rq,"yyyy-MM-dd")
format(rq,"hh:nn:ss")
然后再用楼主的方法,,
left(time,len(time)-9))
_1_ 2004-08-08
  • 打赏
  • 举报
回复
format(rq,"yyyy-MM-dd")
format(rq,"hh:nn:ss")
lazygod 2004-08-08
  • 打赏
  • 举报
回复
哦?northwolves(狼行天下)的办法是最好不过
lazygod 2004-08-08
  • 打赏
  • 举报
回复
left(time,len(time)-InStr(1,time,"", vbTextCompare))
事实上是楼上办法的一个缩写。
northwolves 2004-08-08
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
MsgBox DateValue("2004-8-9 12:32:12")
MsgBox TimeValue("2004-8-9 12:32:12")
End Sub
rainstormmaster 2004-08-08
  • 打赏
  • 举报
回复
//但是Access不支持split函数,请问怎么处理?
我的做法是自己封装一个函数,实现split函数的功能:


Private Sub Command1_Click()'调用
Dim s As String
s = "2004-8-9 12:32:12"
Dim buff
buff = mSplit(s, " ")
MsgBox buff(0)
End Sub

Function mSplit(ByVal Text As String, Optional ByVal Delimiter As String = " ", _
Optional ByVal Limit As Long = -1, Optional CompareMethod As _
VbCompareMethod = vbBinaryCompare) As Variant
ReDim res(0 To 100) As String
Dim resCount As Long
Dim length As Long
Dim startIndex As Long
Dim endIndex As Long
length = Len(Text)
startIndex = 1
Do While startIndex <= length And resCount <> Limit
' get the next delimiter
endIndex = InStr(startIndex, Text, Delimiter, CompareMethod)
If endIndex = 0 Then endIndex = length + 1

' make room in the array, if necessary
If resCount > UBound(res) Then
ReDim Preserve res(0 To resCount + 99) As String
End If
' store the new element
res(resCount) = Mid$(Text, startIndex, endIndex - startIndex)
resCount = resCount + 1

startIndex = endIndex + Len(Delimiter)
Loop

' trim unused values
ReDim Preserve res(0 To resCount - 1) As String
' return the array inside a Variant
mSplit = res()
End Function

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧