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

Date format

Scheduled Pinned Locked Moved C#
databasemysqlquestion
7 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.
  • S Offline
    S Offline
    strings
    wrote on last edited by
    #1

    I am using Mysql as my database. i insert the date in the format DateTime.Now.ToString("dd/MM/yyyy") but the strange thing is its gets entered in dd-MM-yyyy format. EVen if i manaually entered the date in database in dd/MM/yyyy and retrive the value from database , its get the format as dd-MM-yyyy. where is the prob???

    A L 2 Replies Last reply
    0
    • S strings

      I am using Mysql as my database. i insert the date in the format DateTime.Now.ToString("dd/MM/yyyy") but the strange thing is its gets entered in dd-MM-yyyy format. EVen if i manaually entered the date in database in dd/MM/yyyy and retrive the value from database , its get the format as dd-MM-yyyy. where is the prob???

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      There is no problem. Databases don't store the date in a specific format - Don't know about MySql, but SQL Server and Sybase store it as a number, its up to your code to display it how you want. There will be a default format from the database (usually defined at server level) and its up to you to format it how you want.

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      S 1 Reply Last reply
      0
      • S strings

        I am using Mysql as my database. i insert the date in the format DateTime.Now.ToString("dd/MM/yyyy") but the strange thing is its gets entered in dd-MM-yyyy format. EVen if i manaually entered the date in database in dd/MM/yyyy and retrive the value from database , its get the format as dd-MM-yyyy. where is the prob???

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

        http://www.plus2net.com/sql_tutorial/date-inserting.php[^]

        1 Reply Last reply
        0
        • A Ashfield

          There is no problem. Databases don't store the date in a specific format - Don't know about MySql, but SQL Server and Sybase store it as a number, its up to your code to display it how you want. There will be a default format from the database (usually defined at server level) and its up to you to format it how you want.

          Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

          S Offline
          S Offline
          strings
          wrote on last edited by
          #4

          Thks for ur reply, but it didn't solved my prob. Interesting thing is date format dd/MM/yyyy in getting inserted correctly on my PC. but when i deployed at client location its gets entered as dd-MM-yyyy format coloum Type is varchar 50.

          L T A 3 Replies Last reply
          0
          • S strings

            Thks for ur reply, but it didn't solved my prob. Interesting thing is date format dd/MM/yyyy in getting inserted correctly on my PC. but when i deployed at client location its gets entered as dd-MM-yyyy format coloum Type is varchar 50.

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

            I think it's a localization problem. Save the date in MySql Date format, not in string.

            1 Reply Last reply
            0
            • S strings

              Thks for ur reply, but it didn't solved my prob. Interesting thing is date format dd/MM/yyyy in getting inserted correctly on my PC. but when i deployed at client location its gets entered as dd-MM-yyyy format coloum Type is varchar 50.

              T Offline
              T Offline
              Tom Deketelaere
              wrote on last edited by
              #6

              strings wrote:

              coloum Type is varchar 50

              There is your problem

              strings wrote:

              date format dd/MM/yyyy in getting inserted correctly on my PC. but when i deployed at client location its gets entered as dd-MM-yyyy format

              When displaying a date (and inserting it into db in a varchar column) without specific formating it will display the way the date settings are set in Windows. First of all you should use a date column type. Then you can either instruct your client on how to change his OS settings (not recommended) or do a format of the date.

              1 Reply Last reply
              0
              • S strings

                Thks for ur reply, but it didn't solved my prob. Interesting thing is date format dd/MM/yyyy in getting inserted correctly on my PC. but when i deployed at client location its gets entered as dd-MM-yyyy format coloum Type is varchar 50.

                A Offline
                A Offline
                Ashfield
                wrote on last edited by
                #7

                strings wrote:

                coloum Type is varchar 50.

                If you had said that in the first place it would have been obvious, its a localisation issue nothing to do with sql. Use a proper datatype and your problem will be solved.

                Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                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