Click here to Skip to main content
15,914,481 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i added time to getdate() , i want to stop when day closed at a end time


like today 26/2/2018 20:00:00 pm i want to stop 27/2/2018 00:00:00 in while loop

What I have tried:

like today 26/2/2018 20:00:00 pm i want to stop 27/2/2018 00:00:00 in while loop
Posted
Updated 26-Feb-18 1:01am

1 solution

Adding an arbitrary time span wouldn't always hit the target. The best you can do is detect when it is greater. Something like:
C#
System.DateTime dt = System.DateTime.Now;
System.TimeSpan duration = new System.TimeSpan(0, 1, 5, 0);

int day = dt.Day;
while (dt.Day == day)
{
  Console.WriteLine(dt.ToString());
  dt = dt.Add(duration);
}
 
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