Sai Stuff to Developers

August 17, 2010

Problem of Date using Culture

Filed under: DotNet — tosaik @ 6:29 pm
Tags:

Hi, I want to share my problem and its solution i found..

Problem : I have developed one client Application in which iam getting data from database in to DataView Object, Now my task is to show the records on the Grid which are greater than or equal to current system date.

To do so i used following code

(overview not exactly)

string today = DateTime.Now.ToString();

dv.RowFilter = string.Format(“TODATE >=#{0}#”, today);

Its working fine on some systems and raising exceptions on some other systems.

Solution : the exact problem is culture the system. When the culture is different what we expecting then its getting execption to fix this problem i coded the above code as follows:

CultureInfo culture = new CultureInfo(“en-US”);

string today = DateTime.Now.ToString(“d”,culture);

dv.RowFilter = string.Format(“TODATE >=#{0}#”, today);

Now this code perfectly works on any ssytem with any culture.

Happy to Share Code ūüôā

Problem of Date with Culture

Filed under: DotNet — tosaik @ 1:55 pm

Hi, I want to share my problem and its solution i found..
Problem : I have developed one client Application in which iam getting data from database in to DataView Object, Now my task is to show the records on the Grid which are greater than or equal to current system date.
To do so i used following code

(overview not exactly)
 string today = DateTime.Now.ToString();
¬†dv.RowFilter = string.Format(“TODATE >=#{0}#”, today);

Its working fine on some systems and raising exceptions on some other systems.

Solution : the exact problem is culture the system. When the culture is different what we expecting then its getting execption to fix this problem i coded the above code as follows:

¬†¬†¬†¬†¬†¬† ¬†CultureInfo culture = new CultureInfo(“en-US”);¬†¬†¬†¬†¬†
¬†¬†¬†¬†¬†¬†¬†¬† string today = DateTime.Now.ToString(“d”,culture);
¬†¬†¬†¬†¬†¬†¬†¬† dv.RowFilter = string.Format(“TODATE >=#{0}#”, today);

Now this code perfectly works on any ssytem with any culture.

Happy to Share Code ūüôā

Create a free website or blog at WordPress.com.

%d bloggers like this: