Excel VBA将1小时添加到日期/时间字符串 [英] Excel VBA Adding 1 hour to a date / time string
本文介绍了Excel VBA将1小时添加到日期/时间字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何建议将不胜感激。
解决方案
将其转换为日期,添加一小时,并使用格式转换回字符串
Private Sub TestIt()
MsgBox AddHour(06/10/15 4:53 pm)
End Sub
公共函数AddHour(ByVal sTime As String)As String
Dim dt As Date
dt = CDate(sTime)
dt = DateAdd(h,1,dt)
AddHour = Format(dt,mm / dd / yy h:nnam / pm)
结束函数
参考:
- VBA格式功能
I have a text string that looks like this: "06/10/15 4:53pm". I want to add 1 hour (60 minutes exactly) to the text string looks like this: "06/10/15 5:53pm"
Any suggestions would be appreciated.
解决方案
Convert it to a date, add an hour, and convert back to string using format
Private Sub TestIt()
MsgBox AddHour("06/10/15 4:53pm")
End Sub
Public Function AddHour(ByVal sTime As String) As String
Dim dt As Date
dt = CDate(sTime)
dt = DateAdd("h", 1, dt)
AddHour = Format(dt, "mm/dd/yy h:nnam/pm")
End Function
Reference:
这篇关于Excel VBA将1小时添加到日期/时间字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文