cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
6542
Views
15
Helpful
5
Replies

How to get tomorrows date in UCCX script

MARK BAKER
Enthusiast
Enthusiast

I am trying to determine how to get tomorrow's date in UCCX. I am wanting to determine if today is the last day of the month by checking if tomorrow is the 1st day of the month. I currently use D[now].date to get today's date in some scripts. I tried the set command tomorrowDate = D[now].date + 1 and it showed 28 when today is the 27th, but I was thinking this was just adding 1 to the number returned by D[now].date and not actually showing the next day's date. I am thinking this might return 32 on Jan. 31st.

Does anyone know how to get an acurate tomorrow's date in UCCX scripting?

Thank you,

Mark

2 Accepted Solutions

Accepted Solutions

nowcommsupport
Beginner
Beginner

Hi Mark,

Is it possible to create two date objects, both with the current date, increment the Day of Month on one and then do a comparison to see if the months of the new and modified dates match?

You should be able to use the Expression Editor to get an idea of what functions are avilable for the object.

This is taken from the definition for the 'setDate()' function on the Oracle website:

Sets the day of the month of this Date object to the specified value. This Date object is modified so that it represents a point in time within the specified day of the month, with the year, month, hour, minute, and second the same as before, as interpreted in the local time zone. If the date was April 30, for example, and the date is set to 31, then it will be treated as if it were on May 1, because April has only 30 days.

See:

http://download.oracle.com/javase/1.4.2/docs/api/java/util/Date.html#setDate%28int%29.

View solution in original post

I feel like a much easier approach would be to keep the current date intact (don't explode it), and just added 1 day to it, whilst storing the result in a tomorrow variable.

 

Example:

Set today = d[now]

Set tomorrow = new Date(today.getTime() + 86400000)

 

86,400,000 = the number of milliseconds in 1 day

 

Therefore, if you wanted to, you could store that in a final long, and jump ahead an arbitrary number of days like this:

final long MILLIS_IN_A_DAY = 86400000L

 

/* Advance the date by three days */

Set future_date = new Date(today.getTime() + (3 * MILLIS_IN_A_DAY))

 

EDIT: 1/18/2019 - Changed the method from getDate to getTime per this thread:

https://community.cisco.com/t5/contact-center/uccx-today-getdate-shows-epoch-time/m-p/3782595

View solution in original post

5 Replies 5

nowcommsupport
Beginner
Beginner

Hi Mark,

Is it possible to create two date objects, both with the current date, increment the Day of Month on one and then do a comparison to see if the months of the new and modified dates match?

You should be able to use the Expression Editor to get an idea of what functions are avilable for the object.

This is taken from the definition for the 'setDate()' function on the Oracle website:

Sets the day of the month of this Date object to the specified value. This Date object is modified so that it represents a point in time within the specified day of the month, with the year, month, hour, minute, and second the same as before, as interpreted in the local time zone. If the date was April 30, for example, and the date is set to 31, then it will be treated as if it were on May 1, because April has only 30 days.

See:

http://download.oracle.com/javase/1.4.2/docs/api/java/util/Date.html#setDate%28int%29.

I got this to work after reading nowcommsupports' post. I hadn't thought of setting a date for a month with 31 days to 32 and having it converted to the 1st day of the next month. I did it something like the below:

variables:

todaysDay     int     D[now].date

todaysMonth  int     D[now].month

todaysYear     int     D[now].year

tomorrowsDate     String     ""

tomorrowsDay     int     0

set tomorrowsDay = todaysDay + 1

set tomorrowsDate = D[todaysMonth + "/" + tomorrowsDay + "/" + todaysYear]

set tomorrowsDay = D[tomorrowsDate].date

If the date is past the last day of the current month, it will role over to the next month. For example, 1/31/11 + 1 = 1/32/11 which is converted to 2/1/11 by the system.

Now I use the int variable "tomorrowsDay" in the routing logic of my script knowing if it equals 1 then today is the last day of the month.

I put this here in case it may help someone else and for my own records. I needed to know if it was the last day of the month for different hours of operation in our help desk script.

Mark

I feel like a much easier approach would be to keep the current date intact (don't explode it), and just added 1 day to it, whilst storing the result in a tomorrow variable.

 

Example:

Set today = d[now]

Set tomorrow = new Date(today.getTime() + 86400000)

 

86,400,000 = the number of milliseconds in 1 day

 

Therefore, if you wanted to, you could store that in a final long, and jump ahead an arbitrary number of days like this:

final long MILLIS_IN_A_DAY = 86400000L

 

/* Advance the date by three days */

Set future_date = new Date(today.getTime() + (3 * MILLIS_IN_A_DAY))

 

EDIT: 1/18/2019 - Changed the method from getDate to getTime per this thread:

https://community.cisco.com/t5/contact-center/uccx-today-getdate-shows-epoch-time/m-p/3782595

Anthony,

As always you come through with the best way to script in UCCX. I appreciate your response. I will more than likely implement this the next time I update the script. I have to leave it as is for now and move on to the next one. It did work the way I did it, but I prefer a cleaner config.

Thanks,

Mark

Thanks for the rating.  We could get into Calendar objects, due to the fact that Date object are deprecated in Java, but then you'd lose a lot of admins who are only familiar with the built-in types in UCCX.

http://download.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.html#roll(int, boolean)

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers