Click here to Skip to main content
15,892,927 members

Comments by Joris Janssens (Top 6 by date)

Joris Janssens 19-Sep-11 17:51pm View    
TimeSpan has some convenient static methods to create an instance. TimeSpan.FromMinutes(double value) will eliminate the need for the conversion to ticks.
=> TimeSpan ts = TimeSpan.FromMinutes(120.75);
Joris Janssens 28-Jul-11 5:01am View    
It was code for WinForms not WPF. I edited my solution with an example for WPF.
Joris Janssens 27-Jul-11 16:30pm View    
very weird, I replicated your code and it's working normally here.

1. does "Console.WriteLine(to.ToString("yyyy-MM-dd HH:mm:ss"));" outputs "2011-01-31 23:59:59"
2. does it work normally when you replace "q = q.Where(n => n.Date <= to);" with the following code:
List<datetime> oldDates = new List<datetime>();
foreach (DateTime n in q) {
if (n.Date <= to) {
oldDates.Add(n);
}
}
foreach (var qq in oldDates) {
//output
}
This also has the benefit that you can step through it to see where it goes horribly wrong. But again, I see now flaw in your code.
Joris Janssens 27-Jul-11 15:18pm View    
You shouldn't get items from feb 2011 or later with that code. One question though: are the february items you get from 2011 (which shouldn't happen) or from earlier years (totally normal)?
Joris Janssens 27-Jul-11 15:12pm View    
"Even if you substract 1 Millisecond, it still remains 01-Fab-2011. "

That's not correct. If you subtract one millisecond you end up with 2011-Jan-31 23:59:59. I would have used "DateTime to = new DateTime(2011, 2,1)" as end date and "n.Date < to" though, it's a bit cleaner.