[TYPO3-dev] bug dbType for date before 01-01-1970

Xavier Perseguers xavier at typo3.org
Thu Sep 25 10:13:06 CEST 2014


Hi Philipp,

> first things first: I've never worked with mysql type date in TYPO3 so I
> can't answer the original question you asked. Sorry. However, here's
> another solution:
> 
> however, I don't store timestamp in the database but mysql date (better
>> idea for birthday, cause I know unix timestamp can't be below 01/01/1970).
>>
> "Unix time is a single signed integer number [...]" [
> http://en.wikipedia.org/wiki/Unix_time#Encoding_time_as_a_number ]
> So a unix timestamp can be negative and you can use it for birthdays. Try
> for yourself if you don't believe me:
> 
> $d = new DateTime();
> $d->setTimestamp(-100000);
> echo $d->format('m:d:Y');

It does not work properly since you cannot do anything useful with pure
MySQL queries on negative timestamp.

When dealing with birthdays, the correct way to handle it is indeed to
use native date and not to rely on a timestamp. Just think about a real
life use case: retrieving anyone birthday for current month... you
should try when storing the birthday as a timestamp, you will have much
fun, either do it in pure mysql and not being able to get a proper
resultset for older people or perform a full table scan in PHP (loop
over every record) to filter in your code.

Kind regards

-- 
Xavier Perseguers
TYPO3 CMS Team Member

TYPO3 .... inspiring people to share!
Get involved: http://typo3.org




More information about the TYPO3-dev mailing list