How to check 2 variable values in if condition using vbscript ?

snehalj 0 Tallied Votes 534 Views Share

above code not working, y is 2010 and year0 is also 2010, as per my knowledge Equal should be displayed as output, but the condition does not get equal.
Pls help me for this.

year1 =rs.fields("FinYear") 
year0 = Mid(year1,1,4)'first year
year1= Mid(year1,5,4)'second year 
y = Year(Now())
if y = year0 then 
Response.Write "Equal"
Response.End 						
end if
Baradaran 1 Junior Poster in Training

Hi,
what is rs.fields("FinYear")? Is it a date? Is it the year?

I don't understand why you are using mid. If you want to extract the year from a date, simply use datepart, as following:

Response.Write DatePart("YYYY", Date())

This would result in 2010.

If this is not what you want, please let me know the value of rs.fields("FinYear").

snehalj 0 Light Poster

hi
sorry i forget to write that,
"20102011" is get stored in FinYear or any other year in this format

year1 =rs.fields("FinYear") 
year0 = Mid(year1,1,4)'first year
year1= Mid(year1,5,4)'second year 
mon =rs.fields("iMonth")
y = Year(Now())
m = Month(Now())
if  cStr(y)= year0 then

the problem is solved using cStr function.
n by using Mid function "20102011" gets seperated as 2010 and 2011

Thank u

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.