Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Date fromat problem

Date fromat problem

Scheduled Pinned Locked Moved Visual Basic
helpquestion
13 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tamimi Code
    wrote on last edited by
    #1

    hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??

    When you get mad...THINK twice that the only advice Tamimi - Code

    P G S D 4 Replies Last reply
    0
    • T Tamimi Code

      hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??

      When you get mad...THINK twice that the only advice Tamimi - Code

      P Offline
      P Offline
      PandemoniumPasha
      wrote on last edited by
      #2

      hi, provide the format in the tostring() function. try this: yourLabel.Text = yourDateTimeObject.ToString("mm/dd/yy")'or ("dd/mm/yy") or whaterver acceptable format. hope this helps

      regards :)

      T 1 Reply Last reply
      0
      • P PandemoniumPasha

        hi, provide the format in the tostring() function. try this: yourLabel.Text = yourDateTimeObject.ToString("mm/dd/yy")'or ("dd/mm/yy") or whaterver acceptable format. hope this helps

        regards :)

        T Offline
        T Offline
        Tamimi Code
        wrote on last edited by
        #3

        thank you .. but i have no problem with displaying format, the problem is how to save the date in different formats. check this

        When you get mad...THINK twice that the only advice Tamimi - Code

        P 1 Reply Last reply
        0
        • T Tamimi Code

          thank you .. but i have no problem with displaying format, the problem is how to save the date in different formats. check this

          When you get mad...THINK twice that the only advice Tamimi - Code

          P Offline
          P Offline
          PandemoniumPasha
          wrote on last edited by
          #4

          where exactly do you want to save it? you could use the various properties like day, month, year ... provided by the datatime object to create a string that you like and save it to ....

          regards :)

          T 1 Reply Last reply
          0
          • P PandemoniumPasha

            where exactly do you want to save it? you could use the various properties like day, month, year ... provided by the datatime object to create a string that you like and save it to ....

            regards :)

            T Offline
            T Offline
            Tamimi Code
            wrote on last edited by
            #5

            1119 wrote:

            you could use the various properties like day, month, year

            actually this is the way i used to solve it. but i don't think it is the best way to solve the problem thank you

            When you get mad...THINK twice that the only advice Tamimi - Code

            P 1 Reply Last reply
            0
            • T Tamimi Code

              1119 wrote:

              you could use the various properties like day, month, year

              actually this is the way i used to solve it. but i don't think it is the best way to solve the problem thank you

              When you get mad...THINK twice that the only advice Tamimi - Code

              P Offline
              P Offline
              PandemoniumPasha
              wrote on last edited by
              #6

              Tamimi - Code wrote:

              actually this is the way i used to solve it. but i don't think it is the best way to solve the problem

              the best way depends upon where you want to store the data. you have not made it clear where you want to save it? i asked you in earlier post. if you are saving the data in a database then you will have to store the datetime object, but if you are storing it in a text file, you can't do that. you will have to format it. for example save the year,month,day... in a file and use it when you want to create a datetime object: datetime dt = new datetime(year,month,day) or you can save the ticks and use it to create the object when you read from the file like: datetime dt = new datetime(ticks) hope this helps.

              regards :)

              1 Reply Last reply
              0
              • T Tamimi Code

                hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??

                When you get mad...THINK twice that the only advice Tamimi - Code

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                Where are you going to save it? If you are saving it to a database, you should not save it as a string, but a date. Use the DateTime.ParseExact method to parse the string. You can use any date format that is possible to specify as a format string.

                --- single minded; short sighted; long gone;

                T 1 Reply Last reply
                0
                • T Tamimi Code

                  hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??

                  When you get mad...THINK twice that the only advice Tamimi - Code

                  S Offline
                  S Offline
                  Sathesh Sakthivel
                  wrote on last edited by
                  #8

                  If you are going to save the Date in the DB go with Datetime Format. not by String datatype. In case if you have used the datatype as string then you should go with Use the DateTime.ParseExact method to parse the string.

                  Regards, Satips.:rose:

                  1 Reply Last reply
                  0
                  • T Tamimi Code

                    hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??

                    When you get mad...THINK twice that the only advice Tamimi - Code

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    Wy are you getting this from a label? Why not just get the date/time value from the original variable that set the label's date? No conversion and no parsing will be involved then.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

                    1 Reply Last reply
                    0
                    • G Guffa

                      Where are you going to save it? If you are saving it to a database, you should not save it as a string, but a date. Use the DateTime.ParseExact method to parse the string. You can use any date format that is possible to specify as a format string.

                      --- single minded; short sighted; long gone;

                      T Offline
                      T Offline
                      Tamimi Code
                      wrote on last edited by
                      #10

                      hi Guffa : simply my question is : if i have a string contains a date (suppose 17/06/2007 format dd/mm/yyyy) how to convert this value to a valid date if my data base has the date format mm/dd/yyyy (or any date format) ?? thank you

                      When you get mad...THINK twice that the only advice Tamimi - Code

                      D 1 Reply Last reply
                      0
                      • T Tamimi Code

                        hi Guffa : simply my question is : if i have a string contains a date (suppose 17/06/2007 format dd/mm/yyyy) how to convert this value to a valid date if my data base has the date format mm/dd/yyyy (or any date format) ?? thank you

                        When you get mad...THINK twice that the only advice Tamimi - Code

                        D Offline
                        D Offline
                        Dave Kreskowiak
                        wrote on last edited by
                        #11

                        Tamimi - Code wrote:

                        if my data base has the date format mm/dd/yyyy

                        Stop. Database's don't have a format for a date, unless you made the mistake of storing the date as text. Pass the date to a parameter in your SQL insert and you pass this parameter a DateTime value, not a String.

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                             2006, 2007

                        T 1 Reply Last reply
                        0
                        • D Dave Kreskowiak

                          Tamimi - Code wrote:

                          if my data base has the date format mm/dd/yyyy

                          Stop. Database's don't have a format for a date, unless you made the mistake of storing the date as text. Pass the date to a parameter in your SQL insert and you pass this parameter a DateTime value, not a String.

                          A guide to posting questions on CodeProject[^]
                          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                               2006, 2007

                          T Offline
                          T Offline
                          Tamimi Code
                          wrote on last edited by
                          #12

                          Dave Kreskowiak wrote:

                          Stop. Database's don't have a format for a date,

                          in MS server i could enter a date 06/17/2007. but i could not enter 17/06/2007 . can we consider this a date format problem ??

                          When you get mad...THINK twice that the only advice Tamimi - Code

                          D 1 Reply Last reply
                          0
                          • T Tamimi Code

                            Dave Kreskowiak wrote:

                            Stop. Database's don't have a format for a date,

                            in MS server i could enter a date 06/17/2007. but i could not enter 17/06/2007 . can we consider this a date format problem ??

                            When you get mad...THINK twice that the only advice Tamimi - Code

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #13

                            Nope. I call it a validation problem. You're not putting the date entered by the user into a DateTime value. You're just taking the string and putting that directly into an SQL statement. That's a really bad idea. If you use a parameterized query, the parameter will format the DateTime value for any SQL Server localization for you. All you have to do is get the text the user entered into a DateTime value, validate it so it's inside a good date range, then pass it to your SQL code.

                            A guide to posting questions on CodeProject[^]
                            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                 2006, 2007

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups