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. The Lounge
  3. Convert.ToDateTime(bool value) [modified]

Convert.ToDateTime(bool value) [modified]

Scheduled Pinned Locked Moved The Lounge
questionhelp
17 Posts 13 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 jcdevnet

    Have you guys noticed that when you do Convert.ToDateTime the first overload of the function receives a boolean parameter, I was wondering what's the outcome of this, I tried it bool myVar = (Convert.ToDateTime(true))? true : false; DateTime dtVar = Convert.ToDateTime(true); bool boolVar = Convert.ToBoolean(DateTime.Now); and received Invalid Cast Exception, and then I had another question why isn't the compiler catching this invalid cast, well I haven't found a logical way to translate a true to a date time, and I don't expect to, but Why is this overload in the framework to begin with, and why is the error at runtime. Anyway any Ideas on what Date Time is True ??? And what Date Time is False ?? -- modified at 12:31 Monday 5th March, 2007

    The things we leave behind are nothing but... well i guess i'm not that wise after all....

    V Offline
    V Offline
    Vega02
    wrote on last edited by
    #5

    It's likely for signature consistency with the other routines in the Convert class. You're experiencing proper behavior. From Reflector: Convert.ToDateTime: public static DateTime ToDateTime(bool value) { return ((IConvertible) value).ToDateTime(null); } Boolean.ToDateTime: DateTime IConvertible.ToDateTime(IFormatProvider provider) { throw new InvalidCastException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("InvalidCast_FromTo"), new object[] { "Boolean", "DateTime" })); }

    1 Reply Last reply
    0
    • J jcdevnet

      Have you guys noticed that when you do Convert.ToDateTime the first overload of the function receives a boolean parameter, I was wondering what's the outcome of this, I tried it bool myVar = (Convert.ToDateTime(true))? true : false; DateTime dtVar = Convert.ToDateTime(true); bool boolVar = Convert.ToBoolean(DateTime.Now); and received Invalid Cast Exception, and then I had another question why isn't the compiler catching this invalid cast, well I haven't found a logical way to translate a true to a date time, and I don't expect to, but Why is this overload in the framework to begin with, and why is the error at runtime. Anyway any Ideas on what Date Time is True ??? And what Date Time is False ?? -- modified at 12:31 Monday 5th March, 2007

      The things we leave behind are nothing but... well i guess i'm not that wise after all....

      S Offline
      S Offline
      SpaghettiCoding
      wrote on last edited by
      #6

      Would it not have been better to not include that method in the framework so we can get a compile time error as oppose to compiling such illogical behavior and having to deal with the exception at runtime. Then again why would someone want to convert a Boolean to datetime. Batman

      J S 2 Replies Last reply
      0
      • S SpaghettiCoding

        Would it not have been better to not include that method in the framework so we can get a compile time error as oppose to compiling such illogical behavior and having to deal with the exception at runtime. Then again why would someone want to convert a Boolean to datetime. Batman

        J Offline
        J Offline
        jcdevnet
        wrote on last edited by
        #7

        I understand that trying to convert from a boolean to DateTime is ilogical, but then, if you had to, what would the return value for this be ? DateTime dt = Convert.ToDateTime(true); DateTime dt2 = Convert.ToDateTime(false); What assumptions would you have to make to actually implement this method

        The things we leave behind are nothing but... well i guess i'm not that wise after all....

        S 1 Reply Last reply
        0
        • J jcdevnet

          I understand that trying to convert from a boolean to DateTime is ilogical, but then, if you had to, what would the return value for this be ? DateTime dt = Convert.ToDateTime(true); DateTime dt2 = Convert.ToDateTime(false); What assumptions would you have to make to actually implement this method

          The things we leave behind are nothing but... well i guess i'm not that wise after all....

          S Offline
          S Offline
          SpaghettiCoding
          wrote on last edited by
          #8

          Something is only equal to itself and nothing else. So your reference must be a specific datetime as a basis of conversion to Boolean. You seem to be asking for a solution without a point of reference. In that case what is x if x * x = y. ... not enough info to solve.

          1 Reply Last reply
          0
          • S SpaghettiCoding

            Would it not have been better to not include that method in the framework so we can get a compile time error as oppose to compiling such illogical behavior and having to deal with the exception at runtime. Then again why would someone want to convert a Boolean to datetime. Batman

            S Offline
            S Offline
            Shog9 0
            wrote on last edited by
            #9

            SpaghettiCoding wrote:

            Would it not have been better to not include that method in the framework so we can get a compile time error as oppose to compiling such illogical behavior and having to deal with the exception at runtime.

            I suspect that might have caused problems for VB.NET. But then, i use that rational for everything insane in the BCL. It's what keeps me lovin' .NET...

            ----

            It appears that everybody is under the impression that I approve of the documentation. You probably also blame Ken Burns for supporting slavery.

            --Raymond Chen on MSDN

            1 Reply Last reply
            0
            • J jcdevnet

              Have you guys noticed that when you do Convert.ToDateTime the first overload of the function receives a boolean parameter, I was wondering what's the outcome of this, I tried it bool myVar = (Convert.ToDateTime(true))? true : false; DateTime dtVar = Convert.ToDateTime(true); bool boolVar = Convert.ToBoolean(DateTime.Now); and received Invalid Cast Exception, and then I had another question why isn't the compiler catching this invalid cast, well I haven't found a logical way to translate a true to a date time, and I don't expect to, but Why is this overload in the framework to begin with, and why is the error at runtime. Anyway any Ideas on what Date Time is True ??? And what Date Time is False ?? -- modified at 12:31 Monday 5th March, 2007

              The things we leave behind are nothing but... well i guess i'm not that wise after all....

              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #10

              Isn't this a programming question? I love the double standards here. I ask people to look at a post I made in a programming forum, and all I get is 1'd and insulted . This guy asks a REAL programming question, and everyone's ignoring the fact that he plainly broke the rules. Amazing.... well, not really.

              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

              N J 2 Replies Last reply
              0
              • J jcdevnet

                Have you guys noticed that when you do Convert.ToDateTime the first overload of the function receives a boolean parameter, I was wondering what's the outcome of this, I tried it bool myVar = (Convert.ToDateTime(true))? true : false; DateTime dtVar = Convert.ToDateTime(true); bool boolVar = Convert.ToBoolean(DateTime.Now); and received Invalid Cast Exception, and then I had another question why isn't the compiler catching this invalid cast, well I haven't found a logical way to translate a true to a date time, and I don't expect to, but Why is this overload in the framework to begin with, and why is the error at runtime. Anyway any Ideas on what Date Time is True ??? And what Date Time is False ?? -- modified at 12:31 Monday 5th March, 2007

                The things we leave behind are nothing but... well i guess i'm not that wise after all....

                R Offline
                R Offline
                Rob Graham
                wrote on last edited by
                #11

                Sometimes nonsense is just nonsense. But, in any case, as John pointed out, this does not belong in the Lounge...

                P 1 Reply Last reply
                0
                • J jcdevnet

                  Have you guys noticed that when you do Convert.ToDateTime the first overload of the function receives a boolean parameter, I was wondering what's the outcome of this, I tried it bool myVar = (Convert.ToDateTime(true))? true : false; DateTime dtVar = Convert.ToDateTime(true); bool boolVar = Convert.ToBoolean(DateTime.Now); and received Invalid Cast Exception, and then I had another question why isn't the compiler catching this invalid cast, well I haven't found a logical way to translate a true to a date time, and I don't expect to, but Why is this overload in the framework to begin with, and why is the error at runtime. Anyway any Ideas on what Date Time is True ??? And what Date Time is False ?? -- modified at 12:31 Monday 5th March, 2007

                  The things we leave behind are nothing but... well i guess i'm not that wise after all....

                  D Offline
                  D Offline
                  David Stone
                  wrote on last edited by
                  #12

                  This honestly belongs more over in the brand new What The...? forum[^]. :)

                  1 Reply Last reply
                  0
                  • realJSOPR realJSOP

                    Isn't this a programming question? I love the double standards here. I ask people to look at a post I made in a programming forum, and all I get is 1'd and insulted . This guy asks a REAL programming question, and everyone's ignoring the fact that he plainly broke the rules. Amazing.... well, not really.

                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                    N Offline
                    N Offline
                    NormDroid
                    wrote on last edited by
                    #13

                    Reminds me once again the episode in the simpsons "Frank Grimes".

                    .net is a box of never ending treasures, every day I get find another gem.

                    1 Reply Last reply
                    0
                    • R Rob Graham

                      Sometimes nonsense is just nonsense. But, in any case, as John pointed out, this does not belong in the Lounge...

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #14

                      Perhaps in "What the..." then. Convert should be deprecated.

                      1 Reply Last reply
                      0
                      • J jcdevnet

                        Have you guys noticed that when you do Convert.ToDateTime the first overload of the function receives a boolean parameter, I was wondering what's the outcome of this, I tried it bool myVar = (Convert.ToDateTime(true))? true : false; DateTime dtVar = Convert.ToDateTime(true); bool boolVar = Convert.ToBoolean(DateTime.Now); and received Invalid Cast Exception, and then I had another question why isn't the compiler catching this invalid cast, well I haven't found a logical way to translate a true to a date time, and I don't expect to, but Why is this overload in the framework to begin with, and why is the error at runtime. Anyway any Ideas on what Date Time is True ??? And what Date Time is False ?? -- modified at 12:31 Monday 5th March, 2007

                        The things we leave behind are nothing but... well i guess i'm not that wise after all....

                        P Offline
                        P Offline
                        Pete OHanlon
                        wrote on last edited by
                        #15

                        Surely the question is, why would anyone want to do this?

                        Deja View - the feeling that you've seen this post before.

                        1 Reply Last reply
                        0
                        • realJSOPR realJSOP

                          Isn't this a programming question? I love the double standards here. I ask people to look at a post I made in a programming forum, and all I get is 1'd and insulted . This guy asks a REAL programming question, and everyone's ignoring the fact that he plainly broke the rules. Amazing.... well, not really.

                          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                          -----
                          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                          J Offline
                          J Offline
                          jcdevnet
                          wrote on last edited by
                          #16

                          You see is not actually a question, It was something that I found funny, and wanted to share with everyone, also I was putting the theme on the table of what implementation and assumptions you would have to make in order to convert from boolean to DateTime and from DateTime to boolean, just wanted to make you think for a second.

                          The things we leave behind are nothing but... well i guess i'm not that wise after all....

                          1 Reply Last reply
                          0
                          • J jcdevnet

                            Have you guys noticed that when you do Convert.ToDateTime the first overload of the function receives a boolean parameter, I was wondering what's the outcome of this, I tried it bool myVar = (Convert.ToDateTime(true))? true : false; DateTime dtVar = Convert.ToDateTime(true); bool boolVar = Convert.ToBoolean(DateTime.Now); and received Invalid Cast Exception, and then I had another question why isn't the compiler catching this invalid cast, well I haven't found a logical way to translate a true to a date time, and I don't expect to, but Why is this overload in the framework to begin with, and why is the error at runtime. Anyway any Ideas on what Date Time is True ??? And what Date Time is False ?? -- modified at 12:31 Monday 5th March, 2007

                            The things we leave behind are nothing but... well i guess i'm not that wise after all....

                            P Offline
                            P Offline
                            peterchen
                            wrote on last edited by
                            #17

                            jcdevnet wrote:

                            Anyway any Ideas on what Date Time is True ??? And what Date Time is False ??

                            If you suffer from explosive diarrhea, maybe it's not time for a date :rolleyes:


                            Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
                            We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
                            Linkify!|Fold With Us!

                            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