jcampanali
asked on
Display First Day of Month C#
Hello,
I'm trying to avoid using Left/Right properties to extract numbers that will built a date like 11/1/2010-basically I want to display the current month, current year with day 1. Here's what I have thus far...
tmpExDate = Strings.Left(Convert.ToStr ing(Module 1.ExDateVa l), 2); //ExDateVal is a DateTime variable
tmpExDate = tmpExDate + "-1-";
tmpExDate = tmpExDate + Strings.Right(Convert.ToSt ring(Modul e1.ExDateV al), 4);
I'm trying to avoid using Left/Right properties to extract numbers that will built a date like 11/1/2010-basically I want to display the current month, current year with day 1. Here's what I have thus far...
tmpExDate = Strings.Left(Convert.ToStr
tmpExDate = tmpExDate + "-1-";
tmpExDate = tmpExDate + Strings.Right(Convert.ToSt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
DateTime dt = DateTime.Now;
string s = string.Format("{0:D2}-1-{1:D4}", dt.Month, dt.Year);
DateTime now = DateTime.Now;
DateTime firstDayofMonth = new DateTime(now.Year, now.Month, 1);
string s = firstDayofMonth.ToShortDat eString();
DateTime firstDayofMonth = new DateTime(now.Year, now.Month, 1);
string s = firstDayofMonth.ToShortDat
DateTime firstDayofMonth = DateTime.Today.AddDays(-(D ateTime.To day.Day - 1));
Open in new window