notification me befor 1 day?

fatmir

New member
Joined
Dec 1, 2020
Messages
1
Programming Experience
Beginner
hi can you help me i want to make notification MessageBox.Show
i want to filter wich datetime in my columns is correct time and notification me -1 day
example :

columns value is 05.12.2020
i want to notification me on 04.12.2020 with MessageBox.Show(" Tommorow in 05.12.2020 you have a plan blblb");

my dateGridView name is : dateGridView1
my columns name is Data and its on cell [4]
i hope you understand me for every date i want to notification me befor 1 day
 

Attachments

  • Capture.JPG
    Capture.JPG
    92.7 KB · Views: 20
Last edited:
Solution
Wouldn't this add a day, as you're subtracting a negative value:
C#:
var span = TimeSpan.FromDays(-1);
var targetDate = date - span;
Regardless, it would be easier to do this:
C#:
var targetDate = date.AddDays(-1);
So put the date into a DateTime and then subtract a TimeSpan that contains one day. That should give you the date when the notification should be fired. Next you check if the current date is that computed date. If so, then show the notification.
Some pseudo code that assumes that your column already contains DateTime values:
C#:
var date = (DateTime) dateGridView.Row[0].Cells[4].Value;
var span = TimeSpan.FromDays(-1);
var targetDate = date - span;
if (targetDate.Date == DateTime.Now.Date)
    MessageBox.Show("Today is the day.");
 
Wouldn't this add a day, as you're subtracting a negative value:
C#:
var span = TimeSpan.FromDays(-1);
var targetDate = date - span;
Regardless, it would be easier to do this:
C#:
var targetDate = date.AddDays(-1);
 
Solution
Yup. Good catch!
 
Back
Top Bottom