Days Of A Month

Sort:
You are not authorized to post a reply.
Author
Messages
Ruma Malhotra
Veteran Member
Posts: 412
Veteran Member

    If year 2007 then days in feb is 28

    if year is 2008 then days is 29. does anyone know how to calculate the days in a month in a year?

     

    Any help is appreciated.

     

    Thanks,

    ruma.

    John Henley
    Senior Member
    Posts: 3348
    Senior Member
      I don't think there is built-in function in Crystal to do that. You can probably write a formula that uses the DatePart() function and the 'y' argument (days in year) and 'd' argument (day part of the date).
      Thanks for using the LawsonGuru.com forums!
      John
      Chris Martin
      Veteran Member
      Posts: 277
      Veteran Member
        Try the "mod" operator in Crystal. For example...

        if year(CurrentDate) mod 4 =0 then 29 else 28

        This should work if you are trying to calc the # of days in Feb. I'm not actually testing this in Crystal so apologies for any syntax errors
        k-rock
        Veteran Member
        Posts: 142
        Veteran Member
          what is the desired result? What are you using the result for?
          Ruma Malhotra
          Veteran Member
          Posts: 412
          Veteran Member

            I actually was able to calculate the days. The only issue was to calculate the days in Feb and this is how I was able to calculate it :

            If (Remainder(Year(CurrentDate), 4) = 0 and
                    Remainder(Year(CurrentDate), 100) <> 0) or

                         (Remainder(Year(CurrentDate), 400) = 0)

                               then 29

                                        else 28

             

            Thanks for all help.

            Matthew Nye
            Veteran Member
            Posts: 514
            Veteran Member
              thought Id share this as I recently resolved this with a custom formula, exactly what you did but maybe a bit more reusable:

              function (numbervar argYear)
              if argYear mod 400 = 0 then true
              else if argYear mod 100 = 0 then false
              else if argYear mod 4 = 0 then true
              else false
              If any of my answers were helpful an endorsement on LinkedIn would be much appriciated! www.linkedin.com/pub/matthew-nye/1a/886/760/
              Char
              Veteran Member
              Posts: 62
              Veteran Member
                Day(dateadd('d',-1, date(yyyy,mm,dd))) So basically you subtract one day from the first day of the month following the month you want to know how many days there are. The day() function willl return 29 where the date you entered was 2008,03,01. The reason I put in the date() function is to show you how you would programatically create it
                You are not authorized to post a reply.