can formatDateTime() return day of week as a number?

7
If I use formatDateTime($Server_DateTime,'EEEE') I get the text of the weekday returned, such as Sunday, Monday... etc. I am using this value in subsequent flow to search for matching records. I am worried that this value is English language, and in otrher environments it may return the weekdays in different languages. I would prefer to be able to return the weekday as an integer, 0, 1 etc. Does anyone know of a function to return the DayOfWeek as an integer? I looked on http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html and tried formatDateTime($Server_DateTime,'F'), but that seems to return the week number in the month. In the parent Java DateFormat class there seems to be: DAY-OF-WEEK-FIELD public static final int DAY-OF-WEEK-FIELD (underscores replaced with hyphens by me) Can this be used in Mendix and if so, how? UPDATE after answer: I have tested and 'F' definitely returns the number of the week of the month, calculated from the 1st day of the month. SOLUTION after responses: Solved this by creating a Java action. Needed to add line near top of javasource (not in USER CODE section): import java.util.Calendar; then user code as follows: // BEGIN USER CODE Calendar cal = Calendar.getInstance(); cal.setTime(InputDate); int dow = cal.get(Calendar.DAY_OF_WEEK); String tmpStr = Integer.toString(dow); return tmpStr; // END USER CODE
asked
3 answers
10

To get around this Java Date problem, you could use the Calendar class in a Java action.

Some sample code:

    SimpleDateFormat regularDateFormat = new SimpleDateFormat("dd:MM:yyyy");
    Date date = regularDateFormat.parse("08:04:2010");
    System.out.println("date: " + date.toString());
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    System.out.println("day of week: " + calendar.get(Calendar.DAY_OF_WEEK));

This will produce the following output:

date: Thu Apr 08 00:00:00 CEST 2010
day of week: 5

You could easily build a java action that takes a date as input and returns the day number

answered
8

My suggestion would be: parseInteger(formatDateTime($CreationDate, 'u'))
This wil return a number where monday is 1 and sunday is 7.

answered
4

I would say from the Java documentation that F returns the number you want. Have you tested it with different input dates?

answered