Click here to Skip to main content
16,021,810 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
See more:
How can i get the first day (Eg: Sunday or Monday...) of current month.
Posted
Updated 26-Nov-18 0:02am

DateTime now = DateTime.Now;
DateTime firstDay = new DateTime(now.Year, now.Month, 1);
string dayOfFirstDay = firstDay.DayOfWeek.ToString();
 
Share this answer
 
Anyways friends.. thanx to all

i got solution

C#
String day = System.DateTime.Now.DayOfWeek.ToString();
Int date = System.DateTime.Now.Day;
String fdm = System.DateTime.Now.AddDays(-Convert.ToDouble (date-1)).DayOfWeek.ToString();
 
Share this answer
 
Comments
Jani Giannoudis 18-Sep-11 14:09pm    
Use DateTime.Now only one time in case the day changes between the calls. See solution of Bill.
VB
Dim s = "201208"
Dim firstDay = Date.ParseExact(s, "yyyyMM", Nothing)
Dim lastDay = firstDay.AddMonths(1).AddDays(-1)
Dim year = firstDay.Year
 
Share this answer
 
Comments
[no name] 23-Aug-13 7:38am    
The question was asked and answered 2 years ago. There is no real need to answer it again.
Member 10996508 27-Aug-14 16:53pm    
How to get 4 weeks of current month in that format?
july 1 - july 8
july 9 - july 16
july 17 - july 24
The idea is that you use DateSerial to get 1st day of the month:-
VB Code:
DateSerial(Year(dtDate), Month(dtDate), 1)

To get the last day of the month you add a month to the first day then subtract 1 day which gives you
VB Code:
DateAdd("d", -1, DateAdd("M", 1, DateSerial(Year(dtDate), Month(dtDate), 1)))
 
Share this answer
 
Comments
CHill60 26-Nov-18 3:23am    
Reason for my downvote: The question clearly stated that the result was to be the name of the day "(Eg: Sunday or Monday...)" and the first day of the current month. It is also clearly tagged as C# (not the VB.NET) solution that your have provided. Also, although you have used DateSerial instead of new DateTime the principle is identical to Solution 3
If you are going to answer old posts that already have solutions, make sure that you are bringing something new to the thread, that your answer is complete (in this case, what is dtDate?), and that it is relevent.
Be aware that very members bother to tell you why they have downvoted or reported
It will return the first day of the current month.
string firstDayOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).DayOfWeek.ToString();
 
Share this answer
 
Comments
CHill60 26-Nov-18 6:20am    
Reason for my downvote: Not really any different to Solution 3 from 7 years ago. All you have done is put everything onto a single line, whereas Solution 3 breaks it down to make it clearer what is happening.
If you are going to post solutions to previously answered posts please try to make sure that you are bringing something new to the thread. Most members will not bother to point this out by the way
[no name] 26-Nov-18 6:34am    
Yes. I did not check the third solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900