cancel
Showing results for 
Search instead for 
Did you mean: 

Date display

Former Member
0 Kudos

Hi ,

i have a table with data and in one column i have dates.I have 2 dates in row in dates column(yyyy-mm--dd) format .How to change these two dates in dd/mm/yyyy and some rows i have only single date.

_____________

2009-11-09

2008-12-01

____________

With Regards,

suresh

Accepted Solutions (1)

Accepted Solutions (1)

pravesh_verma
Active Contributor
0 Kudos

Hi Suresh,

Create a simple data type of type java.sql.date and give the format in it as "dd/MM/yyyy". Please revert back incase you need any further information on this.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

HI Praveen,

I created //new SimpleDateFormat("dd/mm/yyyy").format(new SimpleDateFormat("dd/mm/yyyy").parse(NDD));

But its not working the column displaying empty.

Regards,

Suresh

pravesh_verma
Active Contributor
0 Kudos

Hi Suresh,

Try this code


DateFormat df=new SimpleDateFormat("dd/MM/yyyy");
Date date=new Date();
String s=df.format(date);

I hope this should work

Thanks and Regards

Pravesh

Former Member
0 Kudos

HI Praveen,

I have used your code but its not working.It showing empty column.

Regards,

Suresh

pravesh_verma
Active Contributor
0 Kudos

Hi Suresh,

Try the first approach which I have told you. If that does not work try this code once again.


DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String s=df.format(new Date(2009,11,9)); // I am passing the date in the format function in Year-Month-Date format.

This should work, its working on my system. If this does not work please revert back.

Also please note that you are confusing with my name. Its Pravesh not Praveen.

Thanks and Regards

Pravesh

Former Member
0 Kudos

Hi Pravesh,

Its not working in my appication. I have already dates in my table.

Stirng dt = care.get dates();

In this dt i have dates in this format (yyyy-mm-dd).now i want to cahnge to dd/mm/yyyy.

Regards,

Suresh

Former Member
0 Kudos

Hi Suresh,

If this column is showing date in "yyyy-mm-dd" format and of type String data type then use the following code to change to your required format.


Pass your required format to dateFormat.
	    public static String convertStringDateToRequiredFormat(String strDate,String dateFormat)
	    {
	    	/**
	    	 * The expected input date is yyyy-MM-dd MM/dd/yyyy. 
	    	 * If input is not in expected format, strDate will be returned back.
	    	 */
	    	try{
	    		String dtArray[] = strDate.split("-");
		
				int month = Integer.parseInt(dtArray[1]);
				int day = Integer.parseInt(dtArray[2]);
				int year = Integer.parseInt(dtArray[0]);
		
				Calendar cl = Calendar.getInstance();
				cl.set(Calendar.MONTH,--month);
				cl.set(Calendar.DAY_OF_MONTH,day);
				cl.set(Calendar.YEAR,year);
		
				SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
				String dt = sdf.format(cl.getTime());
	    		return dt;
	    	}catch(Exception e){
	    		/**
	    		 * In case of any exception just returning given string
	    		 */
	    		return strDate;    	
	    	}
	    	
	    }

Regards,

Jaya.

pravesh_verma
Active Contributor
0 Kudos

Hi Suresh,

Its quite strange that its not working. It should ideally work.. OK instead of date format try to use this method.

1) Create one method String getFormatedDate(String Date). Go to methods tab of the view to create this method. Give the method name as getFormatedDate with return type String. Add the parameter to this method of type String with name Date.

2) Write this code where you are getting the dates in format (yyyy-mm-dd).


Stirng dt = care.getDates();
String date = getFormatedDate(dt); // This will be your required date in format dd/mm/yyyy

3) In the implementation write this code:


public String getFormatedDate(String date){
String year = date.split("-")[0];
String month = date.split("-")[1];
String day = date.split("-")[2];
	  
String finalDate = day+"/" +month+"/"+ year;
return finalDate ;
}

I am sure this will work atlease. However this is very unusual way of getting the formatted date but I really dont know why the dateFormatter is not working for you..

Please revert back incase you could not solve this issue using this approach. And thanks for correcting the name

Thanks and Regards,

Pravesh

Former Member
0 Kudos

HI Jaya,

Can you please tell me process to create Public Static method in webdybpro.And after i created these method how to call the date column in to my onaction result.

Regards,

Suresh

Former Member
0 Kudos

Hi Suresh,

Create one more value attribute under the node (Which you bind to a table). Chagne the property of calculated attribute to true. Two methods (getter and setter) will be generated for this.

Copy paste the below code in the newly generated getter method.



try{
String strDate = element.getXXXDate(); 
String dateFormat = "dd/MM/yyyy";
// element is one of the input parameter of your getter method which represents the current element of the node.
// I am assuming that the column name which is holding the date in "yyyy-mm-dd" is XXXDate. Change the code to suit your attribute.
	    		String dtArray[] = strDate.split("-");
		
				int month = Integer.parseInt(dtArray[1]);
				int day = Integer.parseInt(dtArray[2]);
				int year = Integer.parseInt(dtArray[0]);
		
				Calendar cl = Calendar.getInstance();
				cl.set(Calendar.MONTH,--month);
				cl.set(Calendar.DAY_OF_MONTH,day);
				cl.set(Calendar.YEAR,year);
		
				SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
				String dt = sdf.format(cl.getTime());
	    		return dt;
	    	}catch(Exception e){
	    		/**
	    		 * In case of any exception just returning given string
	    		 */
	    		return strDate;    	
	    	}

Now, instead of binding the old column to the table, bind the new column (Calculated attribute) to the table. It will show the date in the required format.

Former Member
0 Kudos

HI Pravesh,

As per your code i done the changes but i am getting that

java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1

Can you please solve this error.

Regards,

Suresh

pravesh_verma
Active Contributor
0 Kudos

Hi Suresh,

This can be possible only if the value passed as date to this functionis null or empty. Please add a null value and a empty value check.

Try this code:



public String getFormatedDate(String date){
String finalDate = "";
if(date!=null && !date.equalIgnoreCase("")){
String year = date.split("-")[0];
String month = date.split("-")[1];
String day = date.split("-")[2];
	  
finalDate  = day+"/" +month+"/"+ year;
}
return finalDate ;
}

Please note that if null OR a empty string is passed to this function then this function will just return "". (An empty string)

I hope this solves the issue.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

HI Pravesh,

Thank you. Its working fine but when i have 2 dates in one row at that time the dates are not showing perfectly.Actually my issue is that only when i have single date i am able to change the date format through this code

NDD = care.getNextDD().trim().toString();

NDD = NDD.substring(8)"/"NDD.substring(5,7)"/"NDD.substring(0,4);

But in my rows sometime it will have 2 or 3 dates in dates column.I need to change the entire column in this format not only if i have only 1 date.

Regards,

Suresh

pravesh_verma
Active Contributor
0 Kudos

Hi Suresh,

Uff!!! Finally.. you got the solution.. I would say that just create a function and everytime you are fetching the date just pass it to this function. If you are getting multiple dates then you have to write your logic in such a way that it could be passed to this function seperately and the function can return you the exact value.

There is no other way out. If your question is answered I guess probably you can give the points to the suggestion or close the thread.

If you have any further issues please revert back.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

HI Pravesh,

Actually i am getting dates from RFC.I create element to RFc node and i am fetching the dates column from that FM.

Can you please give solution for if i have multiple dates.

Regards,

Suresh

Former Member
0 Kudos

Hi VJR,

Could you provide solution for this issue.when i have multiple date sin my row how to cahnge that format.

Now if i have single date i am changing the format but wheni have multiple date sin single row i am facing problem.

Please provide your opinion on this issue.

Regards,

Suresh

pravesh_verma
Active Contributor
0 Kudos

Hi Suresh,

This is purely a JAVA code and your technique of how you could distinguish between the multiple dates coming from the RFC element. probably I could just give you a hint.

Let us assume that you are getting the multiples dates seperated by a comma (","). Then the logic should be like:


String NDD = care.getNextDD().trim().toString();
	  
	  String dates[] = NDD.split(",");
	  String tempDate= "";
	  String finalDate = "";
	  
	  if(date.length()>0){
		  tempDate = getFormatedDate(dates[0]);
		  finalDate  = finalDate + tempDate;
	  }

then you could pass each string to the method where you will get the output as the string.

Also you function getFormatedDate should look like this:


public String getFormatedDate(String date){
		  String finalDate = "";
		  if(date!=null && !date.equalsIgnoreCase("")){
		  finalDate = date.substring(8)+"/"date.substring(5,7)"/"+date.substring(0,4);
		  }
		  return finalDate ;

	  }

I hope this could help you to solve the issue. However, you need to decide upon the exact logic which you need to implement in this case.

Thanks and Regards,

Pravesh

Answers (0)