Excel YEAR function in vb.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vasilis X

    Excel YEAR function in vb.net

    Hello.

    I want to use the excel function Year( ) (or Day, Month, Minute etc...)
    in a Visual Basic .net application.

    How can i do this?
    I tried Excel.Worksheet Function but this class doesn't contain these
    functions.
    Is there a similar function in vb.net ? (that take as an argument a single
    number, like in excel)

    Any help will be much appreciated.

    Thank you,
    Vasilis


  • Ken Tucker [MVP]

    #2
    Re: Excel YEAR function in vb.net

    Hi,

    The datetime class has a year function. Not sure if that is exactly
    what you are looking for.



    Ken
    ---------------------
    "Vasilis X" <someone@somewh ere.com> wrote in message
    news:%23iJm4M2k FHA.3316@TK2MSF TNGP14.phx.gbl. ..
    Hello.

    I want to use the excel function Year( ) (or Day, Month, Minute etc...)
    in a Visual Basic .net application.

    How can i do this?
    I tried Excel.Worksheet Function but this class doesn't contain these
    functions.
    Is there a similar function in vb.net ? (that take as an argument a single
    number, like in excel)

    Any help will be much appreciated.

    Thank you,
    Vasilis



    Comment

    • Vasilis X

      #3
      Re: Excel YEAR function in vb.net

      Unfortunatelly the datetime class is not adequate.
      I need the class that takes as a given a float number, not a date value.
      In excel the YEAR function takes as argument a number representing
      the number of days passed since a specific day ( i think the begining
      of the century). The decimal part of this number represents the time.

      So i need a function that takes this specific argument.


      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
      news:OxEIER2kFH A.4000@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Hi,
      >
      > The datetime class has a year function. Not sure if that is
      > exactly
      > what you are looking for.
      >
      > http://msdn.microsoft.com/library/de...syeartopic.asp
      >
      > Ken
      > ---------------------
      > "Vasilis X" <someone@somewh ere.com> wrote in message
      > news:%23iJm4M2k FHA.3316@TK2MSF TNGP14.phx.gbl. ..
      > Hello.
      >
      > I want to use the excel function Year( ) (or Day, Month, Minute etc...)
      > in a Visual Basic .net application.
      >
      > How can i do this?
      > I tried Excel.Worksheet Function but this class doesn't contain these
      > functions.
      > Is there a similar function in vb.net ? (that take as an argument a single
      > number, like in excel)
      >
      > Any help will be much appreciated.
      >
      > Thank you,
      > Vasilis
      >
      >
      >[/color]


      Comment

      • Al Reid

        #4
        Re: Excel YEAR function in vb.net

        "Vasilis X" <someone@somewh ere.com> wrote in message news:OIf10h2kFH A.3656@TK2MSFTN GP09.phx.gbl...[color=blue]
        > Unfortunatelly the datetime class is not adequate.
        > I need the class that takes as a given a float number, not a date value.
        > In excel the YEAR function takes as argument a number representing
        > the number of days passed since a specific day ( i think the begining
        > of the century). The decimal part of this number represents the time.
        >
        > So i need a function that takes this specific argument.
        > [/color]

        Look at the Date.FromOADate method.

        Now.ToOADate will give a double (38561.31951730 3244) that represents the date in the format you are looking for. To get the Year from that double you can use the following:

        Date.FromOADate (38561.31951730 3244).Year

        I hope that helps.

        --
        Al Reid

        Comment

        • Vasilis X

          #5
          Re: Excel YEAR function in vb.net

          Thank you !
          That is exactly what i was looking for !

          "Al Reid" <areidjr@reidDA SHhome.com> wrote in message news:e6CwWo2kFH A.2852@TK2MSFTN GP14.phx.gbl...
          "Vasilis X" <someone@somewh ere.com> wrote in message news:OIf10h2kFH A.3656@TK2MSFTN GP09.phx.gbl...[color=blue]
          > Unfortunatelly the datetime class is not adequate.
          > I need the class that takes as a given a float number, not a date value.
          > In excel the YEAR function takes as argument a number representing
          > the number of days passed since a specific day ( i think the begining
          > of the century). The decimal part of this number represents the time.
          >
          > So i need a function that takes this specific argument.
          > [/color]

          Look at the Date.FromOADate method.

          Now.ToOADate will give a double (38561.31951730 3244) that represents the date in the format you are looking for. To get the Year from that double you can use the following:

          Date.FromOADate (38561.31951730 3244).Year

          I hope that helps.

          --
          Al Reid

          Comment

          Working...