06-23-2009 01:12 AM - edited 03-14-2019 04:15 AM
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?
Solved! Go to Solution.
08-30-2011 08:22 AM
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. =)
06-23-2009 07:47 PM
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
06-24-2009 03:00 PM
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.
08-29-2011 02:03 PM
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.
08-30-2011 07:43 AM
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.
08-30-2011 08:12 AM
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!
08-30-2011 08:22 AM
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. =)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide