Click here to Skip to main content
15,885,158 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a program that prints dates(Fridays) between two dates, code work fine, but I am having some trouble, In Visual Studion it's not printing dayLeft but when I checked the same code at .net fiddle there it print dayLeft, Second thing I want to do how to use Skip() method for skipping the last two Fridays till 14/08/2021 Using the query, and how to add count-down from today to 14/08/2021, I mean days left from today to 14th of August, 2021.


HOW TO DO IT IN SINGLE QUERY THAT PRINT DATES OR ALL FRIDAYS ALSO PERFORM DAYS LEFT CALCULATION


What I have tried:

C#
class Program
   {
       static void Main()
       {
           var dates = new List<DateTime>();

           DateTime from = DateTime.Today;

           DateTime to = new DateTime(2021, 08, 14);

           double dayLeft = to.Subtract(DateTime.Today).TotalDays;

           //var to = DateTime.Today.AddDays(14);

           for (var dt = from; dt <= to; dt = dt.AddDays(1))
           {
               dates.Add(dt);
           }

           var allFridays = dates.Where(x => (int)x.DayOfWeek == 5);





           Console.WriteLine(string.Join(Environment.NewLine, allFridays));
           Console.WriteLine("Days Left are: ", dayLeft);


           Console.ReadKey();
       }
   }
Posted
Updated 25-Mar-21 23:44pm
v2

1 solution

Yes, because your print statement is incorrect. it should include the item reference for the variable:
C#
Console.WriteLine("Days Left are: {0} ", dayLeft);
 
Share this answer
 

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