(年\月\日\时)如何转变为时间?还请帮助!

blue23 2003-07-13 10:35:33
客户想只录入年月日时(不录入分和秒),我如何把
(年月日时)转变为时间变量,以便保存入sql中时间字段?
我想让客户以(年-月-日-时)方式录入
...全文
43 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gpo2002 2003-07-13
  • 打赏
  • 举报
回复
引用部件
Microsoft Masked Edit Control 6.0 (SP3)
自由之眼 2003-07-13
  • 打赏
  • 举报
回复
调用方式
一个例子
Text1.Text = strREV(Text1.Text)
自由之眼 2003-07-13
  • 打赏
  • 举报
回复
写一个转换函数
Private Function strREV(dtrDate As String) As String
Dim strStdioDate As String
Dim strTemp As String
Dim iLen As Integer
iLen = InStrRev(dtrDate, "-")
If iLen > 0 Then
strStdioDate = Left(dtrDate, iLen - 1)
strTemp = Right(dtrDate, Len(dtrDate) - iLen)
strTemp = strTemp & ":00:00"
strStdioDate = strStdioDate & " " & strTemp
strREV = strStdioDate
Else
strREV = dtrDate
End If
End Function
测试在win2000下通过
blue23 2003-07-13
  • 打赏
  • 举报
回复
比如实际接单时间:2003-02-12 10:30:00
可是客户只要求录入2003-02-12-10因为分和秒对他没有用所以他不要求录入
现在的问题就是我如何把他录入的2003-02-12-10转变为正常的时间变量
hiiiiiijiang 2003-07-13
  • 打赏
  • 举报
回复
说详细一点,ok?
rainstormmaster 2003-07-13
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
'没加错误处理,你自己加吧
Dim arrtemp As Variant
arrtemp = Split(Text1.Text, "-")
Dim mydate As Date
mydate = DateSerial(arrtemp(0), arrtemp(1), arrtemp(2)) + TimeSerial(arrtemp(3), 0, 0)
MsgBox Hour(mydate)
MsgBox Day(mydate)
MsgBox Month(mydate)
MsgBox Year(mydate)
End Sub
smalle 2003-07-13
  • 打赏
  • 举报
回复
dateserial()
好像是这个,你查查吧

7,763

社区成员

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

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