VB的數(shù)據(jù)庫操作,我們都知道在Where子句中對(duì)于字符串類型,用單引號(hào)
在莫力達(dá)等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,網(wǎng)絡(luò)營銷推廣,外貿(mào)網(wǎng)站建設(shè),莫力達(dá)網(wǎng)站建設(shè)費(fèi)用合理。
注意:凡是日期、時(shí)間類型,用井號(hào),也就是 #
所以,你的這個(gè)用
select * from 表名 where cdate(起始時(shí)間) between #" + CDate(txtStart.Text) + "# and #" + CDate(txtOver.Text) + “#“
1、如何存入時(shí)間數(shù)據(jù):
在窗體設(shè)計(jì)視圖中,將textbox控件的“控件來源”屬性設(shè)為數(shù)據(jù)表的相應(yīng)字段。
以后在正常打開窗體時(shí),在這個(gè)textbox控件里輸入數(shù)據(jù),數(shù)據(jù)就會(huì)存入到數(shù)據(jù)表中,時(shí)間數(shù)據(jù)也是如此。
2、時(shí)間如何相加:
時(shí)間值在ACCESS中可以用timevalue()函數(shù)可以求出,將17:30換算成17.5再除以24也可求出,1小時(shí)的時(shí)間值就是1/24,然后可以直接加減,最后用format()函數(shù)還原成時(shí)間格式。
一樓風(fēng)中的奶牛的做法很棒,建議樓主采納他的回答。
只是其中有一個(gè)Bug,就是“倒數(shù)第二次累計(jì)分鐘數(shù)為59,累計(jì)秒數(shù)達(dá)到60的時(shí)候,會(huì)出現(xiàn)**:60:**”。例如{"10:57:35", "2:02:51"},我這里做了修改,供參考。
另外,AddByInts中不需要進(jìn)行循環(huán)和Select判斷,可以簡化。
同時(shí),為了說明類和結(jié)構(gòu)的關(guān)系,這里改用類。
也請(qǐng)一樓風(fēng)中的奶牛勿怪罪在下?。?/p>
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim str As String() = {"10:30:35", "2:02:51", "17:00:35", "2:02:51"}
Dim str As String() = {"10:57:35", "2:02:51"}
Dim time As TimeSerial = New TimeSerial
For Each dt As String In str
time.Add(dt)
Next
MsgBox(time.ToString)
End Sub
End Class
Public Class TimeSerial
Public Hour As Integer ' 時(shí)間的小時(shí)部分
Public Minute As Integer ' 時(shí)間的分鐘部分
Public Second As Integer ' 時(shí)間的秒鐘部分
' 合并添加新的時(shí)間值
' param name="value"文本時(shí)間格式(00:00:00)/param
Public Sub Add(ByVal value As String)
Dim arr As String() = Split(value, ":")
Dim dts(arr.Length - 1) As Integer
For i As Integer = 0 To arr.Length - 1
dts(i) = CInt(Val(arr(i)))
Next
AddByInts(dts)
End Sub
' 合并添加新的時(shí)間值
' param name="value"時(shí)間值(僅計(jì)算:時(shí)、分、秒)/param
Public Sub Add(ByVal value As Date)
Dim dts(2) As Integer
dts(0) = value.Hour
dts(1) = value.Minute
dts(2) = value.Second
AddByInts(dts)
End Sub
Private Sub AddByInts(ByVal value As Integer())
Second += value(2)
If Second = 60 Then
Minute += Int(Second / 60)
Second = Second Mod 60
End If
Minute += value(1)
If Minute = 60 Then
Hour += Int(Minute / 60)
Minute = Minute Mod 60
End If
Hour += value(0)
End Sub
' 獲取時(shí)間的文本格式(00:00:00)
Public Overrides Function ToString() As String
Return Hour ":" Minute ":" Second
End Function
End Class
兩種方式自己選用
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = DateTime.Today.Year()
s = s DateTime.Today.Month()
s = s DateTime.Today.Day()
s = s DateTime.Now.Hour()
s = s DateTime.Now.Minute()
s = s DateTime.Now.Second()
MsgBox(s, vbDefaultButton1, Now())
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim s As String
s = Format(Now(), "yyyymmddhhmmss")
MsgBox(s, vbYes, Now())
End Sub