Skip to main content
Level 9
Feb 4, 2016 3:55 PM UTC
Solved

"Error converting value to date", ValueFormat Exception thrown when trying to fetch date property from crx

Hi All,

I am trying to fetch date property from crx as below :

Calendar cal = Node.getProperty("date").getValue().getDate();

"date" is of type "String" and has a value currently of "2014-02-01".

As per one of the article, http://aem.matelli.org/fetching-properties-from-dialogs/  this is one of the way to get the date value

1] Can you please guide me as to where I am missing things and what needs to be corrected.

Any thoughts/pointers on this will be helpful.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Kunal_Gaba_
Kunal_Gaba_Accepted solution
New Member
Feb 5, 2016 4:10 PM UTC

If the property is stored as string in JCR then why are you reading it as date in the JCR API-

Calendar cal = Calendar.getInstance(); String date = node.getProperty("date").getString() SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd"); Date dateObj = formatter.parse(date); cal.setTime(dateObj);

10 replies

Jitendra_S_Toma
Level 10
Feb 4, 2016 3:59 PM UTC

 Does this code return Date object or calender object?

Node.getProperty("date").getValue().getDate();

askdctm wrote...

Hi All,

I am trying to fetch date property from crx as below :

Calendar cal = Node.getProperty("date").getValue().getDate();

"date" is of type "String" and has a value currently of "2014-02-01".

As per one of the article, http://aem.matelli.org/fetching-properties-from-dialogs/  this is one of the way to get the date value

1] Can you please guide me as to where I am missing things and what needs to be corrected.

Any thoughts/pointers on this will be helpful.

 

Translate
askdctmAuthor
Level 9
Feb 4, 2016 4:07 PM UTC

Hi Jitendra,

Thank you for your reply.

As of now, it is not returning anything. It is throwing ValueFormatException.

As oer the  documentation, looks like it should return Calendar object.

Translate
askdctmAuthor
Level 9
Feb 5, 2016 3:23 AM UTC

Hi All,

Any thoughts/pointers on this will be helpful.

Translate
Level 2
Feb 5, 2016 5:43 AM UTC

This would work only if you are using xtype as datetime. That would store it as a Date and then you can retrieve it like you are trying.

Translate
askdctmAuthor
Level 9
Feb 5, 2016 6:02 AM UTC

Hi Abhinav,

Thank you for your reply. 

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/org/apache/jackrabbit/commons/JcrUtils.html lists JcrUtils.getDateProperty. 

Can you please let me know if it will work in the scenario mentioned.

Translate
askdctmAuthor
Level 9
Feb 5, 2016 7:43 AM UTC

Hi All,

Any thoughts/pointers on the above will be helpful.

Translate
Jitendra_S_Toma
Level 10
Feb 5, 2016 8:44 AM UTC

ValueFormatException, this exception occurs because "2014-02-01" isn't Date which JCR supports. Does it?. I guess, "date" property isn't Date type. So, you can't except value in date.

I would recommend you to read "date" property as String and convert it Date object. This is the simplest thing.

Jitendra

Translate
Kunal_Gaba_
Kunal_Gaba_Accepted solution
New Member
Feb 5, 2016 4:10 PM UTC

If the property is stored as string in JCR then why are you reading it as date in the JCR API-

Calendar cal = Calendar.getInstance(); String date = node.getProperty("date").getString() SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd"); Date dateObj = formatter.parse(date); cal.setTime(dateObj);
Translate
kautuk_sahni
Level 9
Feb 8, 2016 6:20 AM UTC

Hi 

Please go through this Stackoverflow article.

Link:- http://stackoverflow.com/questions/22150895/save-date-as-timestamp-in-cq5

// JSP code

<%@page import="java.text.SimpleDateFormat,java.util.Date"%> <% SimpleDateFormat displayDateFormat = new SimpleDateFormat("dd MMM yyyy"); String dateField = properties.get("nameofdatefield", ""); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy"); Date formattedDate = sdf.parse(dateField); String formattedDateStr = displayDateFormat.format(formattedDate); out.println('Example of formated string'+formattedDateStr); %>

 

Reference Forum Thread :- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__1yaj-dear_all_i_have.html

I hope this would help you.

Thanks and Regards

Kautuk Sahni

Translate
Kautuk Sahni
askdctmAuthor
Level 9
Feb 8, 2016 11:15 AM UTC

Hi Jitendra/Kunal/Kautuk/Abhinav,

Thank you for your help here. Followed the thing mentioned above and it worked.

Translate