Last post Feb 04, 2011 12:35 AM by shwetamber
Feb 03, 2011 06:26 AM|shijostephen|LINK
Please tell me the UI culture for date format yyyy-MM-dd hh:mm:ss AM/PM.
Feb 03, 2011 06:38 AM|Mazenx|LINK
Those formats are read from your server cultures definition , so you can go to control panel regional settings , and find what you want there then you can get the suitable culture based on what you want .
Feb 03, 2011 07:02 AM|shijostephen|LINK
I wanted to change the date format to yyyy-MM-dd hh:mm:ss AM/PM.
For that I used the below code
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
objEmployee.JoiningDate = Convert.ToDateTime(objEmployee.JoiningDate);
but the date didn't change, it remained in the dd/MM/yyyy format.
Can u specify, how I need to change my code to achieve this.
Feb 03, 2011 07:15 AM|Mazenx|LINK
you must understand something , that date is originally saved as integer so if your property joiningdate is defined as DateTime then it doesnt have original format , and if you want to save it as string , then simply you can say
Member.JoiningDate = DateTime.Now.ToString("Your format")
Member.JoiningDate = 'DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss AM/PM")
if your datetime is nullable datetime you shall use DateTime.Value.ToString(" your Format")
but be sure you write the a working format , am not sure if your formate is well written ( i mean the am/pm ).
Feb 03, 2011 07:16 AM|shwetamber|LINK
Try This Code with miner change.
IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-US", false);
objEmployee.JoiningDate = DateTime.ParseExact(objEmployee.JoiningDate, "yyyy-MM-dd hh:mm:ss AM/PM", theCultureInfo);
Feb 03, 2011 07:46 AM|shijostephen|LINK
I am getting the error
"String was not recognized as a valid DateTime."
Feb 04, 2011 12:35 AM|shwetamber|LINK
Please check this URL . Hope this will help you.