Click here to Skip to main content
15,905,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to find the name of the day for a given date that is in a variable 'v_DespatchDate'.

DateTime v_todaydt = DateTime.Today;
v_DespatchDate = v_todaydt.AddDays(7).Date.ToString("yyyy/MM/dd");
Posted

DateTime v_todaydt = DateTime.Today;
v_DespatchDate = v_todaydt.AddDays(7).Date.ToString("D");


plz try this................
 
Share this answer
 
Hi

Try like this..


C#
DateTime v_todaydt = DateTime.Today;
      var v_DespatchDate = v_todaydt.AddDays(7).Date.ToString("yyyy/MM/dd");

      DateTime dateTime = DateTime.ParseExact(v_DespatchDate, "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture);

      var dayname = (dateTime.ToString("dddd"));


for casting use : DateTime.ParseExact

for getting day name use : .ToString("dddd")
 
Share this answer
 
Google is your friend: a very quick search found the result in less than 30 seconds: http://msdn.microsoft.com/en-us/library/bb762911(v=vs.110).aspx[^]
In future, please try to do at least basic research yourself, and not waste your time or ours.
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 2-Jan-14 3:08am    
As advised by you have already seen this link. And using that I tried in my code like:
//DateTime dateValue = new DateTime(2008, 6, 11);
//string v_d=dateValue.ToString("dddd");
//Console.WriteLine(dateValue.ToString("dddd")
I tried with the variable like: DateTime dateValue = new DateTime(v_DespatchDate);
It didnt work. The error is: Error 4 Argument '1': cannot convert from 'string' to 'long'.
I just wanted to know how that variable should be used.
Thank you.
OriginalGriff 2-Jan-14 3:52am    
That implies that you are trying to pass a string to a DateTime Constructor:
string v_DespatchDate = v_todaydt.AddDays(7).Date.ToString("yyyy/MM/dd");
DateTime dateValue = new DateTime(v_DespatchDate);
Which is unnecessary, when you have the datetime value in the middle already!
Try
DateTime v_todaydt = DateTime.Today;
DateTime dateValue = v_todaydt.AddDays(7).Date;
string v_DespatchDate = dateValue.ToString("yyyy/MM/dd");
string dayOfWeek = dateValue.ToString("dddd");

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