Change the datetime variable output to a specific format
-
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
-
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
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)
-
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)
-
whenever i try to get value from datetime it show system specific format. this i want to change
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)
-
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
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[^]
-
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)
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.
-
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.
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)
-
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.
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 -
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
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)