Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SSRSVB.NET
i have my code which runs fine, but i want to use my expression if any or can i do in my expression to select only of years,months and days.example if my output is 3 years=3years and not 3years,0month,0days, and 7months should only display 7 months and not 0years,7months,0days as well as days to be 6days rather than 0 years 0months and 6 days.
here is my code in my expression
 
=code.GetCustomDate(avg(Fields!SentenceLength.Value))
 
 
Public Function GetCustomDate(ByVal days As Int32) As String
        Dim objDate1 As DateTime = DateTime.Now()
        Dim objDate2 As DateTime = objDate1.AddDays(-1 * days)
'This has to be modified as not correct.
        Return "Years = " & (objDate1.Year - objDate2.Year) & " Months = " & (objDate1.Month - objDate2.Month) & " Days = " & (objDate1.Day - objDate2.Day)
    End Function
 
thanks in advance
Posted 26-Nov-12 11:51am
menacy279
Edited 26-Nov-12 12:07pm
v3
Comments
Sergey Alexandrovich Kryukov at 26-Nov-12 18:10pm
   
What is "select"? You are calculated some time which is "days days ago", so what? Did you want to achieve something else. --SA
menacy at 26-Nov-12 18:20pm
   
hi thanks for your reply.. i have 2 functions 1 for calculate the range in which i have my Start date and end date.i have been display and find the right Output in average here is my code Public Function NaturalLength(length As integer) As Double 'dim d as Date dim year As double dim month As double dim day As double dim sum as double if length >365.25 then year =length\365.25 length =length Mod 365.25 length =year *365.25 year =cstr(Math.Floor (length\365.25)) year=CInt(fix(length)) 'length =(length Mod 365.25 ) year = length end if if length>=31 And length<366 then month=length\30.4375 length=length Mod 30.4375 length=month * 30.4375 month=cstr(Math.Floor (length\30.4375)) month=CInt(fix(length)) 'length =(length Mod 30.4375) month=length end if if length<31 Then day =length end if sum =(year + month +day) return sum.tostring() 'return sum.tostring(year+"year" +month+"month"+day+"day") End Function on my code above(on my question) i used to display suppose 365 days = 1 year,0 months 0days.which runs fine, as i said i want to display as 1years and not 1 years,0months 0 days.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please see my comment to the question: you either formulate it wrong or do it wrong.
All thinkable questions on the topic are answered here:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^],
http://msdn.microsoft.com/en-us/library/system.timespan.aspx[^]
 
and also:
 
http://msdn.microsoft.com/en-us/library/dd992632.aspx[^],
http://msdn.microsoft.com/en-us/library/ee372286.aspx[^],
http://msdn.microsoft.com/en-us/library/ee372287.aspx[^].
 
Pay attention for the second link: time span and time are different things. If you want to present time span, calculate time span; and your last line doing some operations on the year and month may be conceptually wrong. You can get time span by subtraction operator:
 
Dim timeSpan as System.TimeSpan
timeSpan = objDate2 - objDate1; ' as simple as that
 
And go from there.
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you may need to look at the years, months, days and check to see if they are 0 before building a display string.
 
e.g.
 
if iYear > 0 then
 sDisp = sDisp & iYear.tostring & "Years "
End if
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 424
1 Sergey Alexandrovich Kryukov 336
2 Shai Vashdi 318
3 OriginalGriff 265
4 Abhinav S 150
0 Sergey Alexandrovich Kryukov 9,169
1 OriginalGriff 5,290
2 Peter Leow 4,020
3 Maciej Los 3,535
4 Abhinav S 3,263


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid