fixed generate date function