how to convert datetime to a particular format
<pre><code>private void buildGrid()
{
    this.currentActivities = new XSPIncidentActivityModel.XSPIncidentActivityEntities(BuildEntityConnectionString("XSMDSN")).XSP_IncidentActivity.Where(ia =&gt; ia.IncidentID == this.IncidentID).OrderBy(ia=&gt;ia.CompletionDate).ToList();

    foreach (XSPIncidentActivityModel.XSP_IncidentActivity act in this.currentActivities)
    {
        act.CompletionDate.AddHours(this.TimeZoneOffset); 


        if (act.CompletionDate.IsDaylightSavingTime())
        {
act.CompletionDate.AddHours(-1).ToString("MMM dd, yyyy");
        }
    }

    CommonGrid1.BindDataSource(this.currentActivities);
}
</code></pre>

<p>I have to conert the datetime object to a particular format i.e, currentl;y it displays 9/14/2009 12:20:30 PM</p>

<p>i have to display in this manner 9/14/2009 12:20 PM</p>

<p>by converting it to string string s = String.Format("{0:g}", act.CompletionDate.AddHours(this.TimeZoneOffset));  i can display date time without seconds.</p>

<p>But since the data is coming from sql server i have to dislay the datetime object (act.CompletionDate) in that particular format</p>

<p>i tried this but it isnot working
string[] expectedFormats = {"G", "g", "f" ,"F"};
IFormatProvider culture = new CultureInfo("en-GB", true);
act.CompletionDate = DateTime.ParseExact(s, expectedFormats, culture, DateTimeStyles.AllowWhiteSpaces);</p>
