|
-
Apr 15th, 2010, 03:40 AM
#1
Thread Starter
Member
[RESOLVED] Time comparing Sql Query in VB6
Dear Team
I am making one application in vb6 using sql 2000 as database and i am stucked at one point where i m comparing two times with entered time what i want is i want to check if the entered time is equal to existing timeframe in DB than it should popup a msgbox ,but i think i am making some problem in format thats why i am not able to retrieve it correctly.
I am pasting my code here it is for preventing duplicate time.
Private Sub CheckavAilability()
Dim cbemp As String
cbemp = CboEmp.Text
Dim tilde As Integer
tilde = InStr(1, cbemp, "-") 'finds the character position containing the "~"
Dim eid As Integer
Dim ename As String
eid = Val(Left(cbemp, tilde - 1))
ename = Right(cbemp, Len(cbemp) - tilde)
Dim timestart As String
Dim timeend As String
timestart = Format(dtpDate.Value, "yyyy/mm/dd") & " " & Format(CboStartTime, "hh:mm:ss")
timeend = Format(dtpDate.Value, "yyyy/mm/dd") & " " & Format(CboEndTime, "hh:mm:ss")
Dim strix As String
MsgBox " hi "
Dim XYZ As New ADODB.Recordset
'EmpName=" & CboEmp.Text & "
If XYZ.State = 1 Then XYZ.Close
XYZ.Open "Select * from Tbl_Appointment_Package where EmpID= " & eid & " and StartDate ='" & Format(dtpDate.Value, "yyyy/mm/dd") & " ' and timefrom between '" & timestart & "' and '" & timeend & " ' and timeto between '" & timestart & "' and '" & timeend & " ' ", Cn, 1, 3 'and TimeTo = ' " & str & " ' or TimeTo = ' " & str1 & " ' 'and TimeTo=' " & str1 & " '
'Stop
If XYZ.RecordCount > 0 Then
MsgBox "Sorry Please choose another time frame because Employee is busy at selected time "
CboEndTime.Clear
Exit Sub
Else
'MsgBox "Appointment successfully created"
End If
End Sub
In this code i tried with taking timestart and timeend as date also but in that case it was showing error in query can you please help me regarding this.
in my database timefrom and timeto having smalldatetime format and they r getting saved in dd/mm/yyyy hh:mm:ss format but while retriving i have to retrieve them in yyyy/mm/dd hh:mm:ss format so i am confused regarding these formats can you help me regarding this query.
Thanks in advance
Amit Panchal
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|