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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Conversion from string "18/8/2009" to type Date is not valid...

Conversion from string "18/8/2009" to type Date is not valid...

Scheduled Pinned Locked Moved .NET (Core and Framework)
beta-testinghelptestingquestion
11 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.
  • J Johnkokk

    Ok, here is the problem that drives me nuts. I have a datagrid with various data.The first column is the date of the record and it's a string. The following code gives the error tempor=Month(dgv1(0, counter).Value.ToString) On my PC the code works flawlessly.But when i give the application to someone else for BETA testing, it produces the error. Does it make sense to you ? I also tried all the variation to the code, i could think of, like using cdate and cstr functions, changing the type of the tempor variable to date, string, using the .string or not at the ende of the code, to no avail

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Johnkokk wrote:

    Does it make sense to you ?

    Not exactly; your title says you are converting from the string "18/8/2009", but your code is converting something ToString(). Can you clarify a bit more what is in dgv1(0,counter)?

    J 1 Reply Last reply
    0
    • L Lost User

      Johnkokk wrote:

      Does it make sense to you ?

      Not exactly; your title says you are converting from the string "18/8/2009", but your code is converting something ToString(). Can you clarify a bit more what is in dgv1(0,counter)?

      J Offline
      J Offline
      Johnkokk
      wrote on last edited by
      #3

      The field of the datagrid contains "18/8/2009".This is a string. I am trying to get the month part of this date. On my computer whatever i try WORKS. On the other PC whatever i have tried, DOES NOT. Even if i don't put the .string, DOES NOT work on the BETA tester. To make it simple.How do i get the month part of the above field to use as an index in an array ?

      J 1 Reply Last reply
      0
      • J Johnkokk

        The field of the datagrid contains "18/8/2009".This is a string. I am trying to get the month part of this date. On my computer whatever i try WORKS. On the other PC whatever i have tried, DOES NOT. Even if i don't put the .string, DOES NOT work on the BETA tester. To make it simple.How do i get the month part of the above field to use as an index in an array ?

        J Offline
        J Offline
        Johnkokk
        wrote on last edited by
        #4

        Τhe problem seems to be the regional setting of the other pc, which are different than mine.If they are change to the same as mine, it works Hmmmmm

        T L 2 Replies Last reply
        0
        • J Johnkokk

          Τhe problem seems to be the regional setting of the other pc, which are different than mine.If they are change to the same as mine, it works Hmmmmm

          T Offline
          T Offline
          TheDudeJuan
          wrote on last edited by
          #5

          you could split the string ( string.Split() ) and then take the second index of a string array, then you have the number of the month, maybe you could work with that?

          Here we rest... So why not make the best of it? :D

          L 1 Reply Last reply
          0
          • J Johnkokk

            Τhe problem seems to be the regional setting of the other pc, which are different than mine.If they are change to the same as mine, it works Hmmmmm

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #6

            it seems you don't have a clue. the only thing that could go wrong in tempor=Month(dgv1(0, counter).Value.ToString) is a NullReferenceException due to dgv1 or Value being null. if there is a problem, it is bound to be in a different line. Look at the entire exception.ToString() output, tell your IDE to show line numbers, and get the line at fault. Most likely it is about date formatting. The first thing about it is you have to decide whether you want a user-selected format (through Regional Settings), or a fixed format (specified explicitly in your conversions, see the Parse/TryParse method overloads that take explicit format info). :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            1 Reply Last reply
            0
            • J Johnkokk

              Ok, here is the problem that drives me nuts. I have a datagrid with various data.The first column is the date of the record and it's a string. The following code gives the error tempor=Month(dgv1(0, counter).Value.ToString) On my PC the code works flawlessly.But when i give the application to someone else for BETA testing, it produces the error. Does it make sense to you ? I also tried all the variation to the code, i could think of, like using cdate and cstr functions, changing the type of the tempor variable to date, string, using the .string or not at the ende of the code, to no avail

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #7

              Your problem is that you are storing your dates as strings. THIS IS WRONG AND VERY STUPID. This is error number 1 when a newbie starts working with dates. You should IMMEDIATELY go back and change your date storeage and manipulation from string to datetime. Dates are subject to the computers cultureinfo, this means if the user has not changed the culture of the computer from the default american format (stupid friggin mm/dd/yyyy yank format) your 18 is being read as a MONTH, If it was a datetime format you would not have this problem.

              Never underestimate the power of human stupidity RAH

              J 1 Reply Last reply
              0
              • M Mycroft Holmes

                Your problem is that you are storing your dates as strings. THIS IS WRONG AND VERY STUPID. This is error number 1 when a newbie starts working with dates. You should IMMEDIATELY go back and change your date storeage and manipulation from string to datetime. Dates are subject to the computers cultureinfo, this means if the user has not changed the culture of the computer from the default american format (stupid friggin mm/dd/yyyy yank format) your 18 is being read as a MONTH, If it was a datetime format you would not have this problem.

                Never underestimate the power of human stupidity RAH

                J Offline
                J Offline
                Johnkokk
                wrote on last edited by
                #8

                Although i am not exactly newbie at programming, i admit i am relatively new to .net framework thing. As i said on my second post, the problem was indeed the regional settings.The user had set them to American, and so it was reading 18 as Month, thus the error. The reason i didn't use datetime in the field, is because the data are stored in a MS ACCESS database, and it was giving all sorts of problems trying to use the field.So many different bugs i don't even remember. So i made them strings. However i might give it one more shot to see what happens.

                L M 2 Replies Last reply
                0
                • J Johnkokk

                  Although i am not exactly newbie at programming, i admit i am relatively new to .net framework thing. As i said on my second post, the problem was indeed the regional settings.The user had set them to American, and so it was reading 18 as Month, thus the error. The reason i didn't use datetime in the field, is because the data are stored in a MS ACCESS database, and it was giving all sorts of problems trying to use the field.So many different bugs i don't even remember. So i made them strings. However i might give it one more shot to see what happens.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  I would concur with the comments from Luc & Mycroft. Do not store dates and times as strings, it just leads to exactly this sort of problem. A DateTime value is universal and can be displayed in whatever format is required, and in many cases converted to a non-Gregorian calendar.

                  1 Reply Last reply
                  0
                  • T TheDudeJuan

                    you could split the string ( string.Split() ) and then take the second index of a string array, then you have the number of the month, maybe you could work with that?

                    Here we rest... So why not make the best of it? :D

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #10

                    Not a good answer, study DateTime structure.

                    1 Reply Last reply
                    0
                    • J Johnkokk

                      Although i am not exactly newbie at programming, i admit i am relatively new to .net framework thing. As i said on my second post, the problem was indeed the regional settings.The user had set them to American, and so it was reading 18 as Month, thus the error. The reason i didn't use datetime in the field, is because the data are stored in a MS ACCESS database, and it was giving all sorts of problems trying to use the field.So many different bugs i don't even remember. So i made them strings. However i might give it one more shot to see what happens.

                      M Offline
                      M Offline
                      Mycroft Holmes
                      wrote on last edited by
                      #11

                      Johnkokk wrote:

                      However i might give it one more shot to see what happens.

                      I would strongly recommend trying. You will almost certainly run into malformed dates already in the field which will produce error but then you will be fixing your data :)

                      Never underestimate the power of human stupidity RAH

                      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