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. Change the datetime variable output to a specific format

Change the datetime variable output to a specific format

Scheduled Pinned Locked Moved C#
sysadminhelp
9 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.
  • N Offline
    N Offline
    nitin_ion
    wrote on last edited by
    #1

    I have my system date time format set as "dd-MMM-yy" which outputs datetime as {16-Jun-08 8:30:00 AM} i want to make sure that no matter what the datetime set on system/server datetime always shows it as MM/dd/yyyy i googled a lot with setting culture but none is pointing towards a solution, all are offering solution to convert to string and then change the format but i don't want to change to string instead i want to change the datetime variable output to a specific format any help is apperciated

    Kornfeld Eliyahu PeterK L V 3 Replies Last reply
    0
    • N nitin_ion

      I have my system date time format set as "dd-MMM-yy" which outputs datetime as {16-Jun-08 8:30:00 AM} i want to make sure that no matter what the datetime set on system/server datetime always shows it as MM/dd/yyyy i googled a lot with setting culture but none is pointing towards a solution, all are offering solution to convert to string and then change the format but i don't want to change to string instead i want to change the datetime variable output to a specific format any help is apperciated

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      nitin_ion wrote:

      datetime always shows

      Where?

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      N 1 Reply Last reply
      0
      • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

        nitin_ion wrote:

        datetime always shows

        Where?

        I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

        N Offline
        N Offline
        nitin_ion
        wrote on last edited by
        #3

        whenever i try to get value from datetime it show system specific format. this i want to change

        Kornfeld Eliyahu PeterK 1 Reply Last reply
        0
        • N nitin_ion

          whenever i try to get value from datetime it show system specific format. this i want to change

          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu Peter
          wrote on last edited by
          #4

          Still not clear, but as you posted it in C# forum... Custom Date and Time Format Strings[^]

          I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

          "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

          N 1 Reply Last reply
          0
          • N nitin_ion

            I have my system date time format set as "dd-MMM-yy" which outputs datetime as {16-Jun-08 8:30:00 AM} i want to make sure that no matter what the datetime set on system/server datetime always shows it as MM/dd/yyyy i googled a lot with setting culture but none is pointing towards a solution, all are offering solution to convert to string and then change the format but i don't want to change to string instead i want to change the datetime variable output to a specific format any help is apperciated

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

            There is no variable that is setting the "output format"; there is a culture-setting in Windows, and that is used to format dates if you do not specify your own formatting. If you want to change the setting application-wide, then you'd best set the correct culture for your application, effectively overriding the system wide Windows-setting.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            1 Reply Last reply
            0
            • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

              Still not clear, but as you posted it in C# forum... Custom Date and Time Format Strings[^]

              I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

              N Offline
              N Offline
              nitin_ion
              wrote on last edited by
              #6

              My system date date shows 14-oct-14 so when i use a datetime variable it also give date in the same format. I want to change it to some other format 'en-US'. I can do that by

              DateTime.Now.ToString("MM/dd/yyyy"

              ) but then it is in string I want the DateTime it self to return in the specific format and not as string. This is because my SQL date format is different and when i want to compare dates on SQL then i get issue.

              Kornfeld Eliyahu PeterK D 2 Replies Last reply
              0
              • N nitin_ion

                My system date date shows 14-oct-14 so when i use a datetime variable it also give date in the same format. I want to change it to some other format 'en-US'. I can do that by

                DateTime.Now.ToString("MM/dd/yyyy"

                ) but then it is in string I want the DateTime it self to return in the specific format and not as string. This is because my SQL date format is different and when i want to compare dates on SQL then i get issue.

                Kornfeld Eliyahu PeterK Offline
                Kornfeld Eliyahu PeterK Offline
                Kornfeld Eliyahu Peter
                wrote on last edited by
                #7

                You missed it totally - DateTime is a binary format and for that it has no human-readable presentation. When checking it's value in the debugger the environment uses the default (system) settings to present you with something readable... If you have problem with SQL date comparison you better show us your code so we can see the exact problem...

                I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                1 Reply Last reply
                0
                • N nitin_ion

                  My system date date shows 14-oct-14 so when i use a datetime variable it also give date in the same format. I want to change it to some other format 'en-US'. I can do that by

                  DateTime.Now.ToString("MM/dd/yyyy"

                  ) but then it is in string I want the DateTime it self to return in the specific format and not as string. This is because my SQL date format is different and when i want to compare dates on SQL then i get issue.

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

                  nitin_ion wrote:

                  I want the DateTime it self to return in the specific format and not as string

                  There is no such thing! What you see on screen is ALWAYS a string representation of the data in a DateTime structure. There is NO FORMAT in a DateTime value. It is just a bunch of numbers that represents a Date/Time. The only way you get to see the value is if it is converted to some string format. That format is anything you chose. Now, if you're looking in Visual Studio, it uses the systems culture information as a default format. Now, if you stored your Dates in your database as a string, you SERIOUSLY screwed yourself. DateTime should ALWAYS be stored in the database as a DateTime type, NEVER as a string. Why? Because because as a string representation, any DateTime comparisons or lookups will be done using character string rules, NOT DateTime rules. The two sets of rules are work very differently from each other.

                  A guide to posting questions on CodeProject

                  Click this: Asking questions is a skill. Seriously, do it.
                  Dave Kreskowiak

                  1 Reply Last reply
                  0
                  • N nitin_ion

                    I have my system date time format set as "dd-MMM-yy" which outputs datetime as {16-Jun-08 8:30:00 AM} i want to make sure that no matter what the datetime set on system/server datetime always shows it as MM/dd/yyyy i googled a lot with setting culture but none is pointing towards a solution, all are offering solution to convert to string and then change the format but i don't want to change to string instead i want to change the datetime variable output to a specific format any help is apperciated

                    V Offline
                    V Offline
                    V 0
                    wrote on last edited by
                    #9

                    What people are telling you here is that what you "see" as datetime (in the debugger, in an application, in the database's resultset, ...) is just a representation of the datatype "datetime". Just as 10 is a representation of an integer and "10" is the string representation of the integer 10. Both the string and the integer value have a different "machine value" which is a bunch of 1's and 0's. Same goes for your datetime object. What you see is a representation of the object value which you can change as you wish. Hope this clarifies things for you.

                    V.
                    (MQOTD rules and previous solutions)

                    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