This topic is locked
[SOLVED]

 View As Setting Custom Code

5/21/2013 5:17:24 AM
ASPRunnerPro General questions
A
adnankmk author

I have table employees with the following fields.
emp_id (int)

emp_name (varchar)

posting_date (datetime)

serviceinyear (datetime)
I want on the view page the service of the employees should be displayed. the field "serviceinyear" should display the number of months of service. What custom code should I write in the "view as setting custom code" for "serviceinyear" that calculate the service in months to displayed on the view page.
I used this code. But when i use if condition it gives error. How i should use if condition
strValue=data("Smonth")

posting=data("Posting_Date")

monthDob=DatePart("m",posting)

MonthNow=DatePart("m",date())
if (MonthNow>=monthDob)

monthAge= MonthNow-monthDob;

else

{

var monthAge= 12+MonthNow-monthDob;

}

strValue=monthAge
When i run this code. the if condition gives an error. how should I use the if/else condition to calculate the exact months of age

Sergey Kornilov admin 5/21/2013

What is the error message?

A
adnankmk author 5/22/2013



What is the error message?


It was coding error I solved the problem by using this code.
strValue=data("Smonth")

posting=data("Posting_Date")

yearAge= datediff("yyyy",posting,date())

monthDob=DatePart("m",posting)

MonthNow=DatePart("m",date())

dateDob=DatePart("d",posting)

dateNow=DatePart("d",date())
If MonthNow>=monthDob Then

monthAge= MonthNow-monthDob

else

yearAge=yearAge-1

var monthAge= 12+MonthNow-monthDob

End If

If dateNow>=dateDob Then

dateAge=dateNow-dateDob

else

monthAge=monthAge-1

dateAge=31+dateNow-dateDob

end If

strValue=yearAge &"Year"& monthAge&"Month"&dateAge&"Days"