c# - Get Datetime of month and year -
i trying month range of first of month last 2 days (-2)
so example: may 1st 2015 or 05/01/2015.
i want pull last 2 days end date 04/29/15 , first of month 04/01/15.
so range 04/01/15 - 04/29/15 when current day 05/01/2015.
so if current day 05/02/15 want range 04/01/15 - 04/30/15.
but once hits 05/03/15 switches 05/01/15.
so have far:
static datetime getmonthly = datetime.today.adddays(-2); static string startmonthly = ????? static string endmonthly = getmonthly.tostring("yyyy-mm-dd");
i know how endmonthly not first day of getmontly -2 days.
also need grab year according getmonthly. when 01/01/2016, want grab 12/01/15 - 12/30/15
does know how this?
i know there better way ended doing this:
static datetime getmonthly = datetime.today.adddays(-2); static string startmonthly = getmonthly.year + "/" + getmonthly.month.tostring().padleft(2, '0') + "/" + "01"; static string endmonthly = getmonthly.tostring("yyyy-mm-dd");
just wanted show asks question again.
Comments
Post a Comment