-2

I'm creating a BloodBank application using c# and MySQL and my trouble right now is that I want to create a query with DATEDIFF() function that can calculate the difference in days between a made donation already and a new one from the same person since the same person can only donate blood 60 days after a previous donation. One of the dates is already in my MYSQL database and the other one will be received from a datepicker in a Window form .Net.

I have problem making the connection between the mysql database row for the current person and the info in the new made donation.

At the end I want to check if the difference between donations from a same person(same name and email in my case) is more than 60 days and in that case he can make a donation again.

Radoslav
  • 1
  • 1
  • 1
    Convert the datetime picker in a mysql date https://stackoverflow.com/a/3633356/5193536 and simply Select datediff with the database date and the date from the picker – nbk Aug 26 '19 at 17:34
  • Seems like the simplest thing would be to simply and easily subtract 60 days from Today and run a query to see if there are any records older than that date. With no code it is difficult to understand what the problem is or what the DateTimePicker has to do with anything – Ňɏssa Pøngjǣrdenlarp Aug 26 '19 at 18:21
  • I have a datetimepicker for donations so I can fill the table with different dates since I was working on ths stuff these days and didnt populate the table with a valuable data and was testing if my other queries work. So at the end when I fill the table, its seems more fitting that I have a variety of donation dates. Thanks for you suggestions! – Radoslav Aug 26 '19 at 18:55

1 Answers1

0

First thing that comes to mind is that instead of using a DATEDIFF() function in a query, pull the Date information from the database and put it into a DateTime variable, then run a comparison based on DateTime.Now. If it's more than 60 days, it's good to go, otherwise they can't donate.

Additionally, consider using something other than a name/email combo as your check. Between work and personal emails, I probably have like 5 accounts that I would be able to use within your system.

Conrad37
  • 166
  • 1
  • 17