0

I am trying to write a python statement to calculate a user's dob in a mysql db. The dob is a auto-populated field (based off his profile) in a form that a user fills out.

We write python code directly into the fields in our mysql db that perform calculations on runtime. An example: date.today().strftime("%m-%d-%Y") for today's date.

But I have never used it in reference to another field on the same form, so I am unsure how to do this. I have tried:

(date.today() - dob) / timedelta(days=365.2425).strftime("%m-%d-%Y") 

where dob is the field on the form where the user's date of birth is auto-populated.

What am I missing? I receive a 'syntax error', probably because it doesn't know what the dob variable is, but I don't know how to point to that field's value to make it perform the calc. Any help would be appreciated!

chresse
  • 5,486
  • 3
  • 30
  • 47
nyancat
  • 43
  • 5

1 Answers1

0

So, just in case you find yourself using Python and MySQL, here is the correct answer - this must be placed in a field designated to pull from the db, and depending on the code, it would be:

round(datediff(now(), s.dob))/365.25

or

concat(round(datediff(now(), s.dob))/365.25)

where s.dob is a field in another table. Not sure if this will help anybody, but thought I would post in nevertheless. Thanks!

nyancat
  • 43
  • 5