Friday, May 02, 2025

Breaking News
>> Securing and encrypt View State and Cookies values  >> Page has one or more controls that do not correspond with   >> “The Controls collection cannot be modified because the control contains code blocks”  >> How to fix "Validation(): Element 'xxxx' is not supported  >> How to create a new session in ASP.NET programmatically  >> MySQL Database Backup using mysqldump command    

Editors Picks

Tuesday, November 29, 2011

How to convert a string to a date - .NET sample code

How to convert a string to a date - .NET sample code

public string GetAnalysisTimeDuration(string strFromDate, string strToDate)
{
string strDuration = "";
try
{
DateTime dateStart = Convert.ToDateTime(strFromDate);
DateTime dateEnd = Convert.ToDateTime(strToDate);
if (dateStart.Year != dateEnd.Year)
strDuration = String.Format("{0:MMM d,yyyy}", dateStart) + " - " + String.Format("{0:MMM d,yyyy}", dateEnd);
else
strDuration = String.Format("{0:MMM d}", dateStart) + " - " + String.Format("{0:MMM d,yyyy}", dateEnd);
}
catch (Exception ex)
{

}
return strDuration;
}

 

 

No comments :

Post a Comment

Contact Us

Name

Email *

Message *