How to convert string to date. And how to handle null value and this fails to work when the value is empty or void.
Secondly, How to compare two date values and find the greatest of two. Do we have any built-in function to compare and find the latest date.(We tried to fix this using simple if conditions but this failed to work when the date is null or empty).
Please help.
Q. How to convert string to date. And how to handle null value and this fails to work when the value is empty or void.
Follow-up. Can you provide an example of the text? Is it like Jan-2-15 or February 16th 2016 or?
To answer your date question, you can use the DURATIONDAYS function. It takes to dates and will give you the number of days between them. Using this value you can determine which date was first.
DURATIONDAYS("5/1/2016","5/2/2016") //this returns 1 since the first date is earlier
DURATIONDAYS("5/2/2016","5/1/2016") //this returns -1 since the second date is earlier
DURATIONDAYS("5/2/2016","5/2/2016") //same day returns 0
If you don't hard code in the dates you will need to check to see if you are providing both of them. If not then you need to throw an error. For example
if (date1 <> "") AND (date2 <> "") THEN
local datertn = DURATIONDAYS(date1,date2)
return datertn
else
userok("Invalid date input")
endif
Hopefully this helps. Also the durationdays entry in the centricity help file is useful too. Otherwise can you provide an example of your function?
Brad