Parse Date

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

    Parse Date

    Hi,
    I have some data in the format of yyyymmdd (Int32) that I want to display,
    in a datagrid, formatted in International Date Format dd MM yyyy.

    Any suggestions on an efficient approach?

    Thanks,

    Doug


  • Phill.  W

    #2
    Re: Parse Date

    "Doug Bell" <PoorSupport@vo daphone.com.au> wrote in message
    news:OrkjKSBnFH A.3572@TK2MSFTN GP09.phx.gbl...[color=blue]
    > I have some data in the format of yyyymmdd (Int32) that I want
    > to display in a datagrid, formatted in International Date Format[/color]
    dd MM yyyy.

    Dim i as Integer _
    = <value in form yyyymmdd>
    Dim d as DateTime _
    = CDate( i.ToString( "0000\-00\-00" ) )
    DoSomethingWith ( d.ToString( "dd MMM yyyy" ) )

    HTH,
    Phill W.


    Comment

    • Doug Bell

      #3
      Re: Parse Date

      Thanks Phil, that is fine for taking a value from a single record and
      converting it but I was looking for a way to display the whole datatable in
      a datagrid.

      Doug

      "Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
      news:dd7k12$glt $1@yarrow.open. ac.uk...[color=blue]
      > "Doug Bell" <PoorSupport@vo daphone.com.au> wrote in message
      > news:OrkjKSBnFH A.3572@TK2MSFTN GP09.phx.gbl...[color=green]
      > > I have some data in the format of yyyymmdd (Int32) that I want
      > > to display in a datagrid, formatted in International Date Format[/color]
      > dd MM yyyy.
      >
      > Dim i as Integer _
      > = <value in form yyyymmdd>
      > Dim d as DateTime _
      > = CDate( i.ToString( "0000\-00\-00" ) )
      > DoSomethingWith ( d.ToString( "dd MMM yyyy" ) )
      >
      > HTH,
      > Phill W.
      >
      >[/color]


      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Parse Date

        Doug

        What is the datasource if it is a table than you can maybe add an extra
        table column.

        Than you can use this code in a for loop to fill that extra column.

        Dim intdat As Integer = 20050808 'creating your integer and trying to see if
        I understood you.
        Dim intString As String = intdat.ToString
        Dim myDate As DateTime = DateTime.ParseE xact(intString, "yyyyMMdd", Nothing)

        However you are direct in trouble when you want to add a row because you
        cannot set this in an expression.

        I hope this helps,

        Cor


        "Doug Bell" <PoorSupport@vo daphone.com.au> schreef in bericht
        news:OrkjKSBnFH A.3572@TK2MSFTN GP09.phx.gbl...[color=blue]
        > Hi,
        > I have some data in the format of yyyymmdd (Int32) that I want to display,
        > in a datagrid, formatted in International Date Format dd MM yyyy.
        >
        > Any suggestions on an efficient approach?
        >
        > Thanks,
        >
        > Doug
        >
        >[/color]


        Comment

        • Doug Bell

          #5
          Re: Parse Date

          Thanks Cor,
          I was hoping to find a way to parse or format the field but adding a column
          is an acceptable solution.

          Doug

          "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
          news:e1Tek$BnFH A.3408@tk2msftn gp13.phx.gbl...[color=blue]
          > Doug
          >
          > What is the datasource if it is a table than you can maybe add an extra
          > table column.
          >
          > Than you can use this code in a for loop to fill that extra column.
          >
          > Dim intdat As Integer = 20050808 'creating your integer and trying to see[/color]
          if[color=blue]
          > I understood you.
          > Dim intString As String = intdat.ToString
          > Dim myDate As DateTime = DateTime.ParseE xact(intString, "yyyyMMdd",[/color]
          Nothing)[color=blue]
          >
          > However you are direct in trouble when you want to add a row because you
          > cannot set this in an expression.
          >
          > I hope this helps,
          >
          > Cor
          >
          >
          > "Doug Bell" <PoorSupport@vo daphone.com.au> schreef in bericht
          > news:OrkjKSBnFH A.3572@TK2MSFTN GP09.phx.gbl...[color=green]
          > > Hi,
          > > I have some data in the format of yyyymmdd (Int32) that I want to[/color][/color]
          display,[color=blue][color=green]
          > > in a datagrid, formatted in International Date Format dd MM yyyy.
          > >
          > > Any suggestions on an efficient approach?
          > >
          > > Thanks,
          > >
          > > Doug
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: Parse Date

            Doug,
            In addition to the other comments. I would recommend adding a second column
            of type DateTime to your data table.

            You could try using an Expression Column that converts from an Integer into
            a Date.


            I would look at using modulus & division to split the int32 into year, month
            & day, then use Convert & '+' to convert this into a string, and finally use
            Convert to convert the string into a DateTime.

            Seeing as how messy that formula might be, I would consider using a simple
            for loop to update each row:


            Something like (untested):
            For Each row As DataRow in table.Rows
            Dim yyyymmdd As Integer = DirectCast(row! yyyymmdd, Integer)
            Dim yyyy As Integer = yyyymmdd \ 10000
            Dim mm As Integer = (yyyymmdd \ 100) Mod 100
            Dim dd As Integer = yyyymmdd Mod 100
            row!theDateTime = New DateTime(yyyy, mm, dd)
            Next

            FWIW: I normally encapsulate the conversion from Integer to DateTime in its
            own routine.

            Alternatively I would consider using DataTable.Event s to "compute" the
            DateTime column, post if you want an example of this.

            Hope this helps
            Jay

            "Doug Bell" <PoorSupport@vo daphone.com.au> wrote in message
            news:OrkjKSBnFH A.3572@TK2MSFTN GP09.phx.gbl...
            | Hi,
            | I have some data in the format of yyyymmdd (Int32) that I want to display,
            | in a datagrid, formatted in International Date Format dd MM yyyy.
            |
            | Any suggestions on an efficient approach?
            |
            | Thanks,
            |
            | Doug
            |
            |


            Comment

            Working...