Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix timestamp and mysql date: birthdate

Tags:

date

php

unix

mysql

I have a really basic question concerning unix timestamp and mysql date. I'm trying to build a small website where users can register and fill in their birthdate.

Problem is that unix starts with Jan 01 1970. Now if i calculate age for users, form dates like date('m.d.Y', $unix_from_db) and so on it will fail with users older that 40 years, right?

So what would be the rigth way for doing this. Sorry, for basic question like this, but I'm inexperienced with php and mysql.

//Edit: Thank you all. I got confused, because, date('m.d.y',mktime(0,0,0,1,1,1890)) and date('m.d.y',-2000) returned 01.01.70 - next time I'll study manual more carefully. I was able to fix my site, thanks again. Too bad I can accept only one answer, they were all equally good.

like image 953
Mikk Avatar asked Dec 09 '22 16:12

Mikk


2 Answers

Unix timestamps for times before 1970 are negative integers, counting the number of seconds until jan 1 1970.

For example, 2/13/1943 is -848343600

like image 58
seventeen Avatar answered Dec 21 '22 13:12

seventeen


So what? Arithmetic works with negative numbers. When they start the epoch makes no difference as long as it's used consistently.

Negative numbers are people too! Don't discriminate! It hurts their feelings.

like image 38
Jay Avatar answered Dec 21 '22 13:12

Jay