Implement the date function, patch from Pavel