Sai Stuff to Developers

August 17, 2010

Problem of Date using Culture

Filed under: DotNet — tosaik @ 6:29 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 🙂


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: