How to convert date to string value?

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

    How to convert date to string value?

    Hi expert,

    I have a data field (birthdate) contains a datetime datatype
    (mm/dd/yyyy), how can I convert to mmdd??
    say, the birthday is 8/1/1979 and convert to mmdd

    DOB = DS.Tables("Acct InfoTble").Rows (3)("BRTHDATE")
    strResult.Inser t(12, DOB.PadLeft(37, " "))

    ---------------------------------------------------------------------------------------------------

    Public Function GenerateA(ByRef strEmpID As String)
    Dim strResult As New System.Text.Str ingBuilder
    Dim GPConnection As SqlConnection
    Dim dr As SqlDataReader
    Dim GPDataset As New DataSet

    GPConnection = New
    SqlConnection(" ............... ............... ............... ")
    Dim GPDataAdapter As New SqlDataAdapter( "SELECT
    LASTNAME,FRSTNA ME,BRTHDATE FROM UPR00102 where EmployID=' " +
    strEmpID + "'", GPConnection)

    Dim EfundAcct As String
    Dim LName as string
    Dim FName as string
    Dim DOB as string

    GPConnection.Op en()
    GPDataAdapter.F ill(GPDataset, "AcctInfoTb le")
    Dim DS As DataSet = New DataSet
    LName = DS.Tables("Acct InfoTble").Rows (1).Item("LASTN AME")
    FName = DS.Tables("Acct InfoTble").Rows (2)("LASTNAME")
    DOB = DS.Tables("Acct InfoTble").Rows (3)("BRTHDATE")

    ............... .....
    'Position 13 16N First Name
    strResult.Inser t(12, FName.PadLeft(1 6, " "))
    ............... .....
    'Position 37 4A Birthdate
    strResult.Inser t(12, DOB.PadLeft(37, " "))

    GPConnection.Di spose()
    Return strResult.ToStr ing
    End Function

    *-----------------------*
    Posted at:

    *-----------------------*
  • Herfried K. Wagner [MVP]

    #2
    Re: How to convert date to string value?

    "JenHu" <jenniferhu46@h otmail-dot-com.no-spam.invalid> schrieb:[color=blue]
    > I have a data field (birthdate) contains a datetime datatype
    > (mm/dd/yyyy), how can I convert to mmdd??
    > say, the birthday is 8/1/1979 and convert to mmdd[/color]

    \\\
    Dim s As String = _
    Date.ParseExact ( _
    "8/1/1979", _
    "d\/M\/yyyy", _
    Nothing _
    ).ToString("MMy yyy")
    ///

    --
    Herfried K. Wagner [MVP]
    <URL:http://dotnet.mvps.org/>


    Comment

    • Cor Ligthert

      #3
      Re: How to convert date to string value?

      JenHu

      \\\
      Dim mystring as string = mydatetimefield .tostring("MMdd ") that is all
      ///

      By the way every "datetime" field in Net is in every culture in the format
      MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.

      I hope this helps

      Cor

      "JenHu" <jenniferhu46@h otmail-dot-com.no-spam.invalid>
      [color=blue]
      > Hi expert,
      >
      > I have a data field (birthdate) contains a datetime datatype
      > (mm/dd/yyyy), how can I convert to mmdd??
      > say, the birthday is 8/1/1979 and convert to mmdd
      >
      > DOB = DS.Tables("Acct InfoTble").Rows (3)("BRTHDATE")
      > strResult.Inser t(12, DOB.PadLeft(37, " "))
      >
      > ---------------------------------------------------------------------------------------------------
      >
      > Public Function GenerateA(ByRef strEmpID As String)
      > Dim strResult As New System.Text.Str ingBuilder
      > Dim GPConnection As SqlConnection
      > Dim dr As SqlDataReader
      > Dim GPDataset As New DataSet
      >
      > GPConnection = New
      > SqlConnection(" ............... ............... ............... ")
      > Dim GPDataAdapter As New SqlDataAdapter( "SELECT
      > LASTNAME,FRSTNA ME,BRTHDATE FROM UPR00102 where EmployID=' " +
      > strEmpID + "'", GPConnection)
      >
      > Dim EfundAcct As String
      > Dim LName as string
      > Dim FName as string
      > Dim DOB as string
      >
      > GPConnection.Op en()
      > GPDataAdapter.F ill(GPDataset, "AcctInfoTb le")
      > Dim DS As DataSet = New DataSet
      > LName = DS.Tables("Acct InfoTble").Rows (1).Item("LASTN AME")
      > FName = DS.Tables("Acct InfoTble").Rows (2)("LASTNAME")
      > DOB = DS.Tables("Acct InfoTble").Rows (3)("BRTHDATE")
      >
      > ............... ....
      > 'Position 13 16N First Name
      > strResult.Inser t(12, FName.PadLeft(1 6, " "))
      > ............... ....
      > 'Position 37 4A Birthdate
      > strResult.Inser t(12, DOB.PadLeft(37, " "))
      >
      > GPConnection.Di spose()
      > Return strResult.ToStr ing
      > End Function
      >
      > *-----------------------*
      > Posted at:
      > www.GroupSrv.com
      > *-----------------------*[/color]


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: How to convert date to string value?

        "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
        > By the way every "datetime" field in Net is in every culture in the format
        > MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.[/color]

        'DateTime' is not stored in string format and doesn't have a format per-se.

        --
        Herfried K. Wagner [MVP]
        <URL:http://dotnet.mvps.org/>


        Comment

        • Cor Ligthert

          #5
          Re: How to convert date to string value?


          "Herfried K. Wagner [MVP]"
          [color=blue][color=green]
          >> By the way every "datetime" field in Net is in every culture in the
          >> format MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.[/color]
          >
          > 'DateTime' is not stored in string format and doesn't have a format
          > per-se.
          >[/color]
          Did I write that?

          What do you want to say with this sentence?

          Cor


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: How to convert date to string value?

            "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue][color=green][color=darkred]
            >>> By the way every "datetime" field in Net is in every culture in the
            >>> format MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.[/color]
            >>
            >> 'DateTime' is not stored in string format and doesn't have a format
            >> per-se.
            >>[/color]
            > Did I write that?[/color]

            You wrote that "every "datetime" field in Net is in every culture in the
            format MM/dd/yyyy/hh/mm/ss", which is either misleading or false.

            --
            Herfried K. Wagner [MVP]
            <URL:http://dotnet.mvps.org/>


            Comment

            • Cor Ligthert

              #7
              Re: How to convert date to string value?

              >>>> By the way every "datetime" field in Net is in every culture in the[color=blue][color=green][color=darkred]
              >>>> format MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.
              >>>
              >>> 'DateTime' is not stored in string format and doesn't have a format
              >>> per-se.
              >>>[/color]
              >> Did I write that?[/color]
              >
              > You wrote that "every "datetime" field in Net is in every culture in the
              > format MM/dd/yyyy/hh/mm/ss", which is either misleading or false.
              >[/color]
              Can you give me than what it is?

              Cor


              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: How to convert date to string value?

                "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue][color=green][color=darkred]
                >>>>> By the way every "datetime" field in Net is in every culture in the
                >>>>> format MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.
                >>>>
                >>>> 'DateTime' is not stored in string format and doesn't have a format
                >>>> per-se.
                >>>>
                >>> Did I write that?[/color]
                >>
                >> You wrote that "every "datetime" field in Net is in every culture in the
                >> format MM/dd/yyyy/hh/mm/ss", which is either misleading or false.
                >>[/color]
                > Can you give me than what it is?[/color]

                It's formatless. In VB6, dates were stored as a 'Double' value. That's not
                the case for .NET. In .NET, 'DateTime' values are stored in a 'Int64'.

                <URL:http://sharedsourcecli .sscli.net/source/browse/sharedsourcecli/clr/src/bcl/system/datetime.cs?rev =1.1.1.1&conten t-type=text/vnd.viewcvs-markup>
                says:

                | // This value type represents a date and time. Every DateTime
                | // object has a private field (Ticks) of type Int64 that stores the
                | // date and time as the number of 100 nanosecond intervals since
                | // 12:00 AM January 1, year 1 A.D. in the proleptic Gregorian Calendar.

                So, on the one hand, there is the internal representation, which doesn't
                have a human-readable format. In this particular case the date and time is
                stored as "the number of 100 nanosecond intervals since 12:00 AM January 1,
                year 1 A.D. in the proleptic Gregorian Calendar". On the other hand, there
                is the string representation of a 'DateTime', which depends on the culture.
                There is no generic format string that applies to all cultures.

                --
                Herfried K. Wagner [MVP]
                <URL:http://dotnet.mvps.org/>


                Comment

                • Cor Ligthert

                  #9
                  Re: How to convert date to string value?

                  Herfried,
                  [color=blue]
                  > So, on the one hand, there is the internal representation, which doesn't
                  > have a human-readable format. In this particular case the date and time
                  > is stored as "the number of 100 nanosecond intervals since 12:00 AM
                  > January 1, year 1 A.D. in the proleptic Gregorian Calendar". On the other
                  > hand, there is the string representation of a 'DateTime', which depends on
                  > the culture. There is no generic format string that applies to all
                  > cultures.
                  >[/color]

                  This is an answer on another question (where did I write that it was in
                  human readable format by instance) or did tell this in connection with a
                  string format.

                  You said that I am misleading when I tell that a datetime is in dotNet
                  always

                  Months-Days-Years-Hours-minutes-seconds

                  So tell than what it is

                  I am not interested in what kind of bit format it is stored in memory at
                  all, DateTime is a value format in Net and a format in a database, which I
                  am thinking from that it is always in the above format. When not, tell than
                  what format it is and not a kind of novel.

                  Cor


                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: How to convert date to string value?

                    "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
                    > You said that I am misleading when I tell that a datetime is in dotNet
                    > always
                    >
                    > Months-Days-Years-Hours-minutes-seconds
                    >
                    > So tell than what it is[/color]

                    It's actually a number of 100 nanoseconds.

                    This value can be /formatted/ in the format you gave using
                    'DateTime.ToStr ing' + a specific format string or may be formatted this way
                    in certain cultures, but 'DateTime' in .NET is not always in the format you
                    gave.
                    [color=blue]
                    > I am not interested in what kind of bit format it is stored in memory at
                    > all, DateTime is a value format in Net and a format in a database, which I
                    > am thinking from that it is always in the above format. When not, tell
                    > than what format it is and not a kind of novel.[/color]

                    I already told you in what format 'DateTime' is stored in .NET.

                    --
                    Herfried K. Wagner [MVP]
                    <URL:http://dotnet.mvps.org/>


                    Comment

                    • Cor Ligthert

                      #11
                      Re: How to convert date to string value?

                      Herfried,

                      I asked you what format than is. I told that it was not needed to tell the
                      "MM-dd-yyyy" format with a "datetime" value. You told that I am *misleading*
                      people.

                      I don't know what "irreführen d" means in German, however the translation
                      from "misleading " in Dutch "misleiden" says that there should be a personal
                      benefit for the one who does that. I cannot see in anyway how I can get a
                      personal benefit by telling what I did, while it is actual even true.

                      You are telling something about the way dates and times are written in
                      different cultures, which has nothing to do with the way datetime values are
                      stored in dotNet.

                      Cor


                      Comment

                      • Herfried K. Wagner [MVP]

                        #12
                        Re: How to convert date to string value?

                        "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
                        > I asked you what format than is.[/color]

                        And I answered this question.
                        [color=blue]
                        > I don't know what "irreführen d" means in German, however the translation
                        > from "misleading " in Dutch "misleiden" says that there should be a
                        > personal benefit for the one who does that. I cannot see in anyway how I
                        > can get a personal benefit by telling what I did, while it is actual even
                        > true.[/color]

                        That's not true for the German language, and I believe it's not true for
                        English. Misleading IMO means that something points somebody in the wrong
                        direction.
                        [color=blue]
                        > You are telling something about the way dates and times are written in
                        > different cultures, which has nothing to do with the way datetime values
                        > are stored in dotNet.[/color]

                        Re-read my post. I was talking about both, the internal representation of
                        'DateTime' ('Int64') /and/ culture-specific formats (format strings).

                        --
                        M S Herfried K. Wagner
                        M V P <URL:http://dotnet.mvps.org/>
                        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                        Comment

                        • Cor Ligthert

                          #13
                          Re: How to convert date to string value?

                          Herfried,

                          Basicly you are right, the datetime is a value what is internaly as well as
                          in a database a tick that start on a certain date.

                          However you started telling that it was "no" string what brought me on the
                          wrong route, because I had not written that either.

                          I have to admit that I wrote it the last weeks in a wrong way in this
                          newsgroup telling that it was internally by Microsoft MM-dd-yyyy.

                          Just to show that I knew it. in past I have sometimes written that it was
                          crazy that they had choosen in SQL this
                          Datetime (SQLSever)

                          Date and time data from January 1, 1753 through December 31, 9999, to an
                          accuracy of one three-hundredth of a second (equivalent to 3.33 milliseconds
                          or 0.00333 seconds). Values are rounded to increments of .000, .003, or .007
                          seconds, as shown in the table.

                          When you read this, than you get the idea that the one who decided this,
                          believes that humans live started at 1753 and SQL server will exist untill
                          the year 9999. However we don't know the religion form the one who decided
                          this.

                          But I have written in this newsgroups for some week that the internal
                          format is MM-dd-yyyy. That is not to correct therefore in future I will
                          write it as DateTime is represented in VSNet as MM-dd-yyyy what is a
                          translation from a tickcount, which starts on a point depending in the
                          source that it is used.

                          So thank you for bringing me on the right track back again, however please
                          next time more in the way of the message before your last one in this
                          thread, and instead of intervals "ticks". The word ticks had triggered me
                          directly what you wanted to say to me.

                          But it stays of course that for somebody who has a problem with "datetime"
                          it is not needed to give the format of that, it is everywhere the same.

                          Cor



                          "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at>[color=blue]
                          > "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=green]
                          >> I asked you what format than is.[/color]
                          >
                          > And I answered this question.
                          >[color=green]
                          >> I don't know what "irreführen d" means in German, however the translation
                          >> from "misleading " in Dutch "misleiden" says that there should be a
                          >> personal benefit for the one who does that. I cannot see in anyway how I
                          >> can get a personal benefit by telling what I did, while it is actual even
                          >> true.[/color]
                          >
                          > That's not true for the German language, and I believe it's not true for
                          > English. Misleading IMO means that something points somebody in the wrong
                          > direction.
                          >[color=green]
                          >> You are telling something about the way dates and times are written in
                          >> different cultures, which has nothing to do with the way datetime values
                          >> are stored in dotNet.[/color]
                          >
                          > Re-read my post. I was talking about both, the internal representation of
                          > 'DateTime' ('Int64') /and/ culture-specific formats (format strings).
                          >
                          > --
                          > M S Herfried K. Wagner
                          > M V P <URL:http://dotnet.mvps.org/>
                          > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>[/color]


                          Comment

                          • Cor Ligthert

                            #14
                            Re: How to convert date to string value?

                            Herfried,

                            Basicly you are right, the datetime is a value what is internaly as well as
                            in a database a tick that start on a certain date.

                            However you started telling that it was "no" string what brought me on the
                            wrong route, because I had not written that either.

                            I have to admit that I wrote it the last weeks in a wrong way in this
                            newsgroup telling that it was internally by Microsoft MM-dd-yyyy.

                            Just to show that I knew it. in past I have sometimes written that it was
                            crazy that they had choosen in SQL this
                            Datetime (SQLSever)

                            Date and time data from January 1, 1753 through December 31, 9999, to an
                            accuracy of one three-hundredth of a second (equivalent to 3.33 milliseconds
                            or 0.00333 seconds). Values are rounded to increments of .000, .003, or .007
                            seconds, as shown in the table.

                            When you read this, than you get the idea that the one who decided this,
                            believes that humans live started at 1753 and SQL server will exist untill
                            the year 9999. However we don't know the religion form the one who decided
                            this.

                            But I have written in this newsgroups for some week that the internal
                            format is MM-dd-yyyy. That is not to correct therefore in future I will
                            write it as DateTime is represented in VSNet as MM-dd-yyyy what is a
                            translation from a tickcount, which starts on a point depending in the
                            source that it is used.

                            So thank you for bringing me on the right track back again, however please
                            next time more in the way of the message before your last one in this
                            thread, and instead of intervals "ticks". The word ticks had triggered me
                            directly what you wanted to say to me.

                            But it stays of course that for somebody who has a problem with "datetime"
                            it is not needed to give the format of that, it is everywhere the same.

                            Cor



                            "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at>[color=blue]
                            > "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=green]
                            >> I asked you what format than is.[/color]
                            >
                            > And I answered this question.
                            >[color=green]
                            >> I don't know what "irreführen d" means in German, however the translation
                            >> from "misleading " in Dutch "misleiden" says that there should be a
                            >> personal benefit for the one who does that. I cannot see in anyway how I
                            >> can get a personal benefit by telling what I did, while it is actual even
                            >> true.[/color]
                            >
                            > That's not true for the German language, and I believe it's not true for
                            > English. Misleading IMO means that something points somebody in the wrong
                            > direction.
                            >[color=green]
                            >> You are telling something about the way dates and times are written in
                            >> different cultures, which has nothing to do with the way datetime values
                            >> are stored in dotNet.[/color]
                            >
                            > Re-read my post. I was talking about both, the internal representation of
                            > 'DateTime' ('Int64') /and/ culture-specific formats (format strings).
                            >
                            > --
                            > M S Herfried K. Wagner
                            > M V P <URL:http://dotnet.mvps.org/>
                            > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>[/color]


                            Comment

                            • Herfried K. Wagner [MVP]

                              #15
                              Re: How to convert date to string value?

                              Cor,

                              "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
                              > So thank you for bringing me on the right track back again, however please
                              > next time more in the way of the message before your last one in this
                              > thread, and instead of intervals "ticks". The word ticks had triggered me
                              > directly what you wanted to say to me.[/color]

                              You are welcome!

                              --
                              M S Herfried K. Wagner
                              M V P <URL:http://dotnet.mvps.org/>
                              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                              Comment

                              Working...