Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Sunday, March 8, 2009

Converting between dd/mm/yyyy and mm/dd/yyyy in C# asp.net

Convert Date from any format to any format
I came across some problem while converting dates in C# between dd/mm/yyyy and mm/dd/yyyy.

Was struggling with this for a long time and got it in one of the sites. here is the solution :

You can change the from to format and see your results.

Courtesy : Kushaal.net


//For ex., Convert MM/dd/YYYY to dd/MM/yyyy

string date = "03/27/2008"; //format is MM/dd/yyyy

DateTimeFormatInfo dateTimeFormatterProvider = DateTimeFormatInfo.CurrentInfo.Clone() as DateTimeFormatInfo;

dateTimeFormatterProvider.ShortDatePattern = "MM/dd/yyyy"; //source date format

DateTime dateTime = DateTime.Parse(date, dateTimeFormatterProvider);

string formatted = dateTime.ToString("dd/MM/yyyy"); //write the format in which you want the date tobe converted

Response.Write("
" + formatted);

Friday, March 6, 2009

Return datatable from Data logic layer in .net C#

One of my frenz asked how to return a datatable today
so i sent a code for him

posting the same here

public DataTable functionname()
{

DataTable dt = new DataTable();

DataSet ds = new DataSet();


ds = sqlhelper.ExecuteDataSet(strconnectionstring,CommandType.StoredProcedure,"Procdedurename",Param);

if (ds.Tables.count > 0 && ds.Tables[0].Rows.Count > 0)
{
dt = ds.Tables[0];
}


return dt;
}