Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi all

VB
Dim type As String
        Try
            Type = "select joindate from employee where emp_id='" & TextBox1.Text & "'"
            If Type > Type + 6 Then


when i am executing this the if condition giving error like can't convert to double..
please tell the problem.
what i am doing is i m taking the joining date and checking it is greater then 6 months from date or not..
Posted
Comments
JF2015 25-Sep-12 6:24am    
This code doesn't make sense - what do you want to achieve?
[no name] 25-Sep-12 6:39am    
i want a condition where if the joindate crosses more then 6 months then i have to enable and disable some option...
i am fetching the joining date from database

Well,

Type is a string.
Then you assign "select joindate from employee where emp_id='" & TextBox1.Text & "'" to the string itself.
And then you are checking if Type is > 6.

6 is a number, not a string, and inside the Type variable you have a string with text, which can't be compared to any number.

You should first execute the database query from which you want to get the joindate and after getting the return value from that query, assign it to a numeric variable that you should compare to the 6.

Good luck!
 
Share this answer
 
SQL
SELECT CASE WHEN(DATEDIFF(MM, JOINDATE, GETDATE()) > 6) THEN 1 ELSE O END AS IsQualified
FROM employee
WHERE ....
 
Share this answer
 
Comments
[no name] 25-Sep-12 6:29am    
what is IsQualified..???
Kuthuparakkal 25-Sep-12 6:32am    
u change it to anything... upto you
VB
Dim Dt As DateTime
        Try
            Dt = GetValueFromDB("select joindate from employee where emp_id='" & TextBox1.Text & "'")
            'To Access Month
            if monthDifference(Dt,system.DateTime.Date) > 6 then
               'Enable -disable controls as your requirement
            End if

VB
Public Function monthDifference(ByVal startDate As DateTime, ByVal endDate As DateTime) As Integer
    Dim t As TimeSpan = endDate - startDate
    Dim difference As Integer = t.Days
    Dim months As Integer = Math.Floor(difference / 30.475)
    Return months
End Function


where GetValueFromDB is some function that takes input Query and gives Output value (all sql functionality are handled inside) ,
and monthDifference is function that will return difference in months when we input two dates as parameter

Happy coding!
:)
 
Share this answer
 
v2
Comments
[no name] 25-Sep-12 6:37am    
what i have to do is if the joining date is greater then 6 months then i have to enable and disable few options..
e.g. if joining>joining+6 then
a.enable=false
end if
please tell me this condition..
Aarti Meswania 25-Sep-12 6:54am    
use this function for getting difference between months

Public Function monthDifference(ByVal startDate As DateTime, ByVal endDate As DateTime) As Integer
Dim t As TimeSpan = endDate - startDate
Dim difference As Integer = t.Days
Dim months As Integer = Math.Floor(difference / 30.475)
Return months

End Function

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900