The result of the UserResponse() function is not a date so you can’t use FormatDate() function. The result is a string. So use SubStr() function to extract first N characters.
Let’s say, we extract 9 characters…and it gives the result 9/7/2010. How about for the date: 12/31/2010…so…for this formula will not work for that date ???
You’re looking at a date + time, correct? You need to find the first space which is used to separate the date from the time and use that as the end point for the substring command.
Hi,
Determine the position of space using Pos function. Like
=Pos(UserResponse(“Enter value(s) for Payment Date:”);" ") will give the position of first space. use this position value in substring to get the string from position number 0 to Position value returned from Pos function.
Here is formula to get the datapart:
=SubStr(UserResponse("Enter value(s) for Payment Date:");0;Pos(UserResponse("Enter value(s) for Payment Date:");" "))
Why don’t you use ToDate() to convert the string back to Date and then format it using FormatDate()? But give much attention to the date format that you have inside ToDate() function, this should exactly match with your input date format.
OK, I must be missing something minor. I’m trying to calculate the number of months between 2 dates entered by the user, so I need to have UserResponse as a date. This variable returns the string “12/1/2010”:
=If Length(UserResponse("Enter value(s) for Payment Date:"))>10 Then FormatDate(ToDate(UserResponse("Enter value(s) for Payment Date:");"");"dd/MM/yyyy") Else FormatDate(ToDate(UserResponse("Enter value(s) for Payment Date:");"MM/dd/yyyy");"dd/MM/yyyy")
But FormatDate returns a string, not a Date. I need to see the UserResponses to Begin Date and End Date as Dates so I can use them in the MonthsBetween function.
then you can just convert it to date and don’t format it,
=If Length(UserResponse("Enter value(s) for Payment Date:"))>10 Then ToDate(UserResponse("Enter value(s) for Payment Date:");"") Else ToDate(UserResponse("Enter value(s) for Payment Date:");"MM/dd/yyyy")
I think there is a simple way of achievening this.
As weare using free standing cell to display the date, i can use the code
ToDate(UserResponse(“Enter value(s) for Payment Date:”);“MM/dd/yyyy”)
to convert the user response into date, and use format number (right click -> format number) to choose from the templates or use custon template.