Bugfix on date function