cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1450
Views
9
Helpful
6
Replies

Increment and decrement dates in UCCX 7.0

James Hawkins
Collaborator
Collaborator

Hi,

I am writing a UCCX script where I use the "Set TodaysDate=D[now]" step to obtain the current date and store it in a date variable in the format June 23, 2009.

I need to write an expression that can increment and/or decrement the date. Does anyone know how to do this using the Expression Lanaguage?

1 Accepted Solution

Accepted Solutions

Great!  I'm glad I was able to shed some light on the topic for you.  Please don't forget to give a rating to helpful posts.  It's like a reward for good behavoir.  =)

Edit: Oops!  I meant for you to rate the post that helped you.  As other users rate the same helpful post, this shows the community exactly how helpful a particular answer/reply is.  It's kind of like how you might use ratings while shopping online, or when deciding if you should watch a certain movie.

Double Edit: I see that the OP is the one who marked my comment as the correct answer, and not BT HelpDesk.  Either, my point still stands.  =)

View solution in original post

6 Replies 6

jason.mcdonald
Beginner
Beginner

I suppose you could do something like this (in integer format mind you)

D[now].dom-1 (which would as you expect take the todays day of the month and decrement it by 1.

Essentially if you made 3 integers you would do something like

Set Month=D[now].month

Set DayofMonth=D[now].dom-1

Set Year=D[now].year

You then can manupulate the date as you see fit (as the integer value), then convert it back to a string after the fact if necessary to your formatting needs.

There is probably a better way to do it but I hope this helps.

Jason

Jason,

Thanks for your response - I will try your suggestion but am not sure what will happen if incrementing/decrementing the DayofMonth causes the value to move to a new month.

In the Expression Language there is a setDate method that looks like it would do what I want but I cannot work out how to use it - I keep getting expression validation errors.

I also want to do this but you can't just increment an integer.  If the current date is the 31st, you'll end up with the 32nd which we all know would be an error.  I hope someone can be of help with this.  Thanks.

BT Helpdesk wrote:

...but you can't just increment an integer

Sure you can.  Or maybe what you meant to write was, "you can't just increment a Date."  But then again, I say, sure you can!

set one_day_in_millis = 86400000L

set my_date = d[now]

set my_date_millis = my_date.getTime()

set my_date_plus_one_millis = my_date_millis + one_day_in_millis

set my_date_plus_one = new Date(my_date_plus_one_millis)

Note: 86400000 is the number of milliseconds in 1 day, therefore, I am increasing, or going forward, by 1 day

That's maybe the long way around it, but I think it illustrates a good point.  Dates in java, are Longs, which hold the number of milliseconds since January 1, 1970 @ 00:00:00.000.  So you can technically work with Dates in Java, like you would any number.  Add, Subtract, or even compare with >, <, ==, etc.

Thanks Anthony!  I knew it had something to do with counting the days as a whole, not as a day of a month or year.  This is exactly the type of thing I was looking for!

Great!  I'm glad I was able to shed some light on the topic for you.  Please don't forget to give a rating to helpful posts.  It's like a reward for good behavoir.  =)

Edit: Oops!  I meant for you to rate the post that helped you.  As other users rate the same helpful post, this shows the community exactly how helpful a particular answer/reply is.  It's kind of like how you might use ratings while shopping online, or when deciding if you should watch a certain movie.

Double Edit: I see that the OP is the one who marked my comment as the correct answer, and not BT HelpDesk.  Either, my point still stands.  =)

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