Tuesday, March 9, 2010

Getting datetime for first day In a Month

protected void Page_Load(object sender, EventArgs e)
{
   DateTime dtRet = GetFirstInMonth(GetDateValue("2010-03-02"));
   Label1.Text = dtRet.ToShortDateString();
}
 
public static DateTime GetFirstInMonth(DateTime dt)
 {
        DateTime dtRet = new DateTime(dt.Year, dt.Month, 1, 0, 0, 0);
        return dtRet;
}
 

Output:
3/1/2010

No comments:

Post a Comment