How to convert the date from bonita format to yyyy/mm/dd?

1
+1
-1

Hi ,

i would like to convert the date that i retrieve with the widget to this format YYYY/mm/dd and then save it into mysql database

Regards

Comments

Submitted by claz08 on Mon, 10/05/2015 - 21:38

I have created this code:

`import java.text.SimpleDateFormat;
import java.util.Date;

public class exemple {
      public static void main(String[ ] arg) {




java.util.Date date = ${date_local};
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String format = formatter.format(date);
System.out.println(format);
      }
}`

Then what i want to do is retrieve the date that the user has selected and then convert its format from this Mon Oct 05 21:11:32 2015 or this DD/MM/YYYY to this YYYY/MM/DD.

i don't know where i can put this code into my workflow in order to do it .

I'm doing this because i need the dates with this format :yyyy/mm/dd , in order to put in a insert query , because my database use this format

regards

Submitted by claz08 on Tue, 10/06/2015 - 17:21

Somebody has any idea?

1 answer

1
0
-1

First, you are probably using Java 8 - in which case drop the java.util.date and use the new java.time imports. Much better for date and time manipulation.

See here for more information:
http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
http://www.vogella.com/tutorials/JavaDateTimeAPI/article.html

Here you can then use DateTimeFormatter.ofPattern("YYYY/MM/DD") construct.

I wouldn't do the conversion in the form, but only in the process stream before the update to the database using a service task (or the task output operation). Or in the SQL statement itself, such as

INSERT INTO custorder VALUES ('Kevin','yes', STR_TO_DATE('1-01-2012', '%d-%m-%Y'));

This is fro PHP so change the formats and variables as necessary...

regards

Comments

Submitted by claz08 on Tue, 10/06/2015 - 18:01

i have created this mysql query , but didn't work:

INSERT INTO it.documentation ('james','a','b', STR_TO_DATE('${fecha}','%Y-%m-%d')

where i have the wrong?

I think that the wrong is in variable ${fecha}.

Submitted by claz08 on Tue, 10/06/2015 - 18:49

i have reviewed the variable that contain the date, that the user has selected, and i see that it saved with this format : 1 de octubre de 2015., this is the reason that why didn't work.

I have changed this format ,but when i execute the process , the format is the same, and finally it didn't work the insert query .

Submitted by Sean McP on Tue, 10/06/2015 - 19:50

Have you tried a hardcoded version of the insert first, with a real date? Try that. Then work on the Bonita version. Use the MySQL Workbench to prove that the SQL works.

Submitted by claz08 on Tue, 10/06/2015 - 20:19

I have tried the insert query with workbench and it worked well .

as yo i say in the previous post , the problem is with the variable that are there in the insert query , because i can see that its value is : 10 october...etc , and not is 2015-01-01 , for example.

so ..
How i can change the format of date variable .?

Submitted by pinerodanie_1404393 on Fri, 07/12/2019 - 09:44

Tengo el mismo problema alguien lo resolvio?

Notifications