Click here to Skip to main content
15,881,791 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have used

 DateTime date = DateTime.Now;
string strDate = date.ToString("d");


Used to fetch system short date time .Then how can i get the short date format from the DateTime(Means currently using format in PC not all the available short date Formats) . How can i match datetime is of which short date format in c# code or vise versa
Posted
Updated 14-Jun-11 20:27pm
v6
Comments
Sandeep Mewara 15-Jun-11 2:19am    
Please edit and rephrase. It's not very clear right now.
myes 15-Jun-11 2:27am    
I guess now it is clear

I think you want to know which short date pattern is used by PC
If yes, use
Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern
 
Share this answer
 
Comments
myes 15-Jun-11 3:24am    
Thank u so much .
Prerak Patel 15-Jun-11 3:29am    
You are welcome. If your problem is solved, mark this as answer.
charles henington 15-Jun-11 19:59pm    
my vote of 5
Do you mean how to tell the what is "11/12/2011"? is 11 a day or a month? How to restore date format from the formatted string representing date. This is impossible. By obtaining formatted string from DateTime structure you loose part of information, that's it.

See:
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^].

This is never needed. Right idea is working with time, not with its string representation, which should be used only on the final stage, for showing it on the UI. By the way, makes sure there is no ambiguity, so the user could always understand what date and time is presented.

—SA
 
Share this answer
 
Comments
parmar_punit 15-Jun-11 2:35am    
good call, my 5
Sergey Alexandrovich Kryukov 15-Jun-11 2:39am    
Thank you.
--SA
Kim Togo 15-Jun-11 3:18am    
Good answer, my 5. Keep date and time in DateTime until it is shown in UI.
Sergey Alexandrovich Kryukov 17-Jun-11 23:07pm    
Thank you, Kim. (Correct note, thank you.)
--SA
I think you mean how can you look up the system number format for dates ? Is it DD/MM or MM/DD ? CultureInfo.CurrentCulture will tell you the current setting, not sure if you can directly access the format from there, but it's the right direction.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900