Posted: 25 Jan 2016 14:54 EST Last activity: 2 Feb 2016 7:09 EST
Unable to convert datetime to yyyy-MM-dd
Is there a function to convert the date format to yyyy-MM-dd and return a date object. I followed the steps in article SA-14171 but it returning me date in this format yyyyMMdd. I'm able to write a function which formats and returns the date as string. but not able to return the date as date object in this format(yyyy-MM-dd)
we have a property Startdate of type Date , it will have the value in yyyyMMdd format , we are using it in a rest service where we send the Startdate in response , the client is expecting the date to be in this format yyyy-MM-dd. I'm able to convert to this format yyyy-MM-dd using function , but i'm able to return only string. When I set a string to date property (Startdate) I get this exception "2015-11-26" is not a date. is there any way we can return a date in this format (yyyy-MM-dd) so that I can set it to property of type date.
Posted: 6 years ago
Posted: 2 Feb 2016 7:09 EST
Thomas Thrien (tquadrat)
Principal Engineer, Technical Support - Runtime Engine
As Paul already said above, Date does not have a format!
I assume that your Startdate property has the type java.util.Date, and that is binary representation of a Time/Date value without a time zone. It can be translated into a String - given the right function is used with the right arguments, that String may have the format "yyyy-MM-dd" as defined by ISO 8601. But giving that String (of type java.lang.String) to a function that takes an argument of type java.util.Date will cause the exception you mention above - as a java.lang.String is by no means a java.util.Date, no matter what content that String has, and if it could be interpreted as a Time/Date value or not.
Using java.util.Date for date-only properties may cause other problems as well as they always have a time component, too. Although the instance as such do not have a time zone, it will be interpreted under some conditions as for the current time zone - what can result in shifting of the resulting day.