I’m trying to find the time between two dates, one being the current day (Today) and the other, a user defined deadline.
I’m working with C# Windows Forms and I’ve used a “date time picker” so that the user can choose a deadline date and I’ve created a string called Today and used
string Today = System.DateTime.Today.ToString("dd-mm-yyyy");
as the current date. But I don’t know how to find the length of time between these two points (since they’re strings), my program is a simple “to do list” where task duration’s are in days and weeks (the “yyyy” is just for aesthetic purposes, it can be removed if necessary).
I’ve had a look over the internet and all I can seem to find is how to do this with “DateTime”s, instead of strings (or am I missing something?).
Any help would be greatly apreciated.
Use the ‘Value’ property of your DateTimePicker to get the DateTime value and use DateTime.Now to get the DateTime value for the current time (in the local timezone).
If you are only subtracting dates (with no time component), access the Date property of both DateTime objects before subtracting.