Get weekday from DateTimeHandler


User could type in “tomorrow”. I will use date.time.handler and get date - but I also want to save name of weekday in a variable. How do I do that?

Hi Raquell,

If you already get the date (suppose that you save the year, month and day in three integer variables called iYear, iMonth and iDay), you can get the name of weekday easily by the following code:

import java.text.SimpleDateFormat
Calendar c = Calendar.getInstance()
c.set(iYear, iMonth-1, iDay)
Date date = c.getTime(); 
def day_of_week = new SimpleDateFormat("EEEE").format(date)

The code above will return the full day of week, e.g. “Monday”. For short forms like “Mon” please replace “EEEE” with “EEE”

You need to add the code in a script node in your flow or in one of the global scripts.



Thanks for answering!

In my case I would like to combine date-time-handler with this.

For example: User picks a date like tomorrow. We get date from date-time-handler but I would also want name of day. So in my usecase I need it for more then just accurate day.

I think if you use the DateTime interpretation its even easier. Suppose that you get the datetime representation in this way:

%DT_DATE_TIME.REC^{dateTimeRepresentation = lob.datetime}

then you can use this code to get te DateTime interpretation:

dateInterpretation = datetime.Handler.interpret(dateTimeRepresentation)

The DateTime interpretation is a map containing the start date, start time, end date (if there is an end date) and end time (if there is an end time):

[date:[start:[2022-04-29], type:point], time:[start:[00:00], type:point]]

then you can easily get the day of week in this way:

weekday =[0].getDayOfWeek()
1 Like

Thanks! That works!

1 Like

By the way the data type of the date in the DateTime interpretation is java.time.LocalDate and the data type of time is java.time.LocalTime