Ramani Sandeep's Blog

DotNetting – Fast , Easy Way of Developing Applications

Posts Tagged ‘string to date conversion asp.net’

string to date conversion asp.net

Posted by Ramani Sandeep on December 28, 2009

There has been always a Problem in working DateTime variable in ASP.NET when you are working on different environments.

So I feel that why not make some short of solution for that. Here i came up with some result. May be there is better alternative.

Create one common class or if you have in your project than all you need to create is static method to convert string into DateTime with ‘MM/dd/yyyy’ Format.

public static DateTime ParseDateFormatToMMDDYYYY(string oDate)
    {
        IFormatProvider fp = new System.Globalization.CultureInfo("en-US");
        return DateTime.ParseExact(oDate, "MM/dd/yyyy", fp);
    }

Once you have created static method now all you have to do is to use it when ever necessary.

 DateTime search_date = Utilities.ParseDateFormatToMMDDYYYY(Request.QueryString["searchDate"].ToString());

Here the format for Date can be Controlled from Utility Class you can make changes as per your requirement.

Hope this will help !!!

Shout it
kick it on DotNetKicks.com

About these ads

Posted in Uncategorized | Tagged: , , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 124 other followers