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. C#
  4. Date Format Problem

Date Format Problem

Scheduled Pinned Locked Moved C#
helpcsharp
9 Posts 4 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.
  • D Offline
    D Offline
    Dotnetkanna
    wrote on last edited by
    #1

    Hi, I finished developing the .net windows application.problem is in date format.the application developed with the date format of "MM/dd/yyyy" with this appication working fine.but now i want to change the dateformat to "dd/MM/yyyy" by setting this format im getting the folling error "String was not regcognized as valid date format". i have to change the format in one place so that it gets effect in all over the application. i have tried withe the below code.but its not working. CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"; culture.DateTimeFormat.LongTimePattern = ""; System.Threading.Thread.CurrentThread.CurrentCulture = culture; Regards Kanna

    C L 2 Replies Last reply
    0
    • D Dotnetkanna

      Hi, I finished developing the .net windows application.problem is in date format.the application developed with the date format of "MM/dd/yyyy" with this appication working fine.but now i want to change the dateformat to "dd/MM/yyyy" by setting this format im getting the folling error "String was not regcognized as valid date format". i have to change the format in one place so that it gets effect in all over the application. i have tried withe the below code.but its not working. CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"; culture.DateTimeFormat.LongTimePattern = ""; System.Threading.Thread.CurrentThread.CurrentCulture = culture; Regards Kanna

      C Offline
      C Offline
      Christo667
      wrote on last edited by
      #2

      I just wrote a quickie C# WinForms application duplicating your code, and it works fine. Ditto with a console app. Is this an ASP.NET app you are working on?

      D 1 Reply Last reply
      0
      • C Christo667

        I just wrote a quickie C# WinForms application duplicating your code, and it works fine. Ditto with a console app. Is this an ASP.NET app you are working on?

        D Offline
        D Offline
        Dotnetkanna
        wrote on last edited by
        #3

        No Yaar,that code will convert to desire format.but while inserting the record im geeting the error.string was not recognized as valid datetime. for this what i have to do.

        G C 2 Replies Last reply
        0
        • D Dotnetkanna

          No Yaar,that code will convert to desire format.but while inserting the record im geeting the error.string was not recognized as valid datetime. for this what i have to do.

          G Offline
          G Offline
          Garth J Lancaster
          wrote on last edited by
          #4

          what sort of database are you using - what is the table/column definition ? I know Oracle has a function like from_date('18052010', 'ddmmyyyy') type of thing (that may not be exact), that works if the column is defined as date or datetime - ie you can use the 'ddmmyyyy' to tell Oracle how to parse the first argument, in this case 18th 05 (May) in 2010, Non American format 'g'

          1 Reply Last reply
          0
          • D Dotnetkanna

            No Yaar,that code will convert to desire format.but while inserting the record im geeting the error.string was not recognized as valid datetime. for this what i have to do.

            C Offline
            C Offline
            Christo667
            wrote on last edited by
            #5

            Oh, it's a database insert issue. What database are you using? MySQL? If MySQL, try yyyy-MM-dd.

            D 1 Reply Last reply
            0
            • C Christo667

              Oh, it's a database insert issue. What database are you using? MySQL? If MySQL, try yyyy-MM-dd.

              D Offline
              D Offline
              Dotnetkanna
              wrote on last edited by
              #6

              IM using MS Sql Server 2005 db.

              C 1 Reply Last reply
              0
              • D Dotnetkanna

                Hi, I finished developing the .net windows application.problem is in date format.the application developed with the date format of "MM/dd/yyyy" with this appication working fine.but now i want to change the dateformat to "dd/MM/yyyy" by setting this format im getting the folling error "String was not regcognized as valid date format". i have to change the format in one place so that it gets effect in all over the application. i have tried withe the below code.but its not working. CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"; culture.DateTimeFormat.LongTimePattern = ""; System.Threading.Thread.CurrentThread.CurrentCulture = culture; Regards Kanna

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

                You need to provide more and accurate information. The error message you have shown is unknown to Google, except for your own message at eggheadcafe; so it must be something your app is generating itself. Check your code for it! Use whatever means you're accustomed to to determine which line is generating the error; then study that method, maybe show it here (inside PRE tags!!!!!!!!!!!!!!!!!!!). If a database is involved, tell is which one; and the field format; and the code that reads/writes the field. Are you using SQLParameter? FWIW: Here[^] us some overall information on datetimes. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read formatted code with indentation, so please use PRE tags for code snippets.


                I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                D 1 Reply Last reply
                0
                • L Luc Pattyn

                  You need to provide more and accurate information. The error message you have shown is unknown to Google, except for your own message at eggheadcafe; so it must be something your app is generating itself. Check your code for it! Use whatever means you're accustomed to to determine which line is generating the error; then study that method, maybe show it here (inside PRE tags!!!!!!!!!!!!!!!!!!!). If a database is involved, tell is which one; and the field format; and the code that reads/writes the field. Are you using SQLParameter? FWIW: Here[^] us some overall information on datetimes. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read formatted code with indentation, so please use PRE tags for code snippets.


                  I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                  D Offline
                  D Offline
                  Dotnetkanna
                  wrote on last edited by
                  #8

                  yes.i agree. the exact message is "String was not recognized as a valid DateTime"

                  1 Reply Last reply
                  0
                  • D Dotnetkanna

                    IM using MS Sql Server 2005 db.

                    C Offline
                    C Offline
                    Christo667
                    wrote on last edited by
                    #9

                    I think we've established that you're getting an Microsoft SQL Server syntax error on an insert, right? Did you check the actual insert statement string in the debugger? That date format is valid for MS SQL, and it's fine with a date-only without time for a DATETIME. At this point without more info (some code), my best guess would be the usual suspects: columns in INSERT statement out of order or a need to quote the fields. Try backquote.

                    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