Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. And see here for current known issues.

New Member

Date Comparison

Hello All,

UCCX 9

Scenario: I would like the script to do a date comparison so that if Today's date is before xx/xx/xx or after xx/xx/xx I can direct it to different steps in the scripts.

I have 3 string variables

Current_Date  - Changes depending on the day

Begin_Date    - 2/1/2014

End_Date      - 2/10/2014

Step 1

I have an IF statement

If Current_Date < Begin_Date

-True Goes to Time_of_Day_check

-False Goes to End_Date_check

Step 2

If the above outcome is False it checks the End_Date

IF Current_Date >End_Date

-True   Goes to Time_of_Day_check

-False Goes to Alternative Time_Of_Day_check

The issues I'm having is with Step 2

When the End_Date is less than 2/6/2014 it works fine.

For example if End_date is 2/3/2014 it goes to True, which is correct.

However,

When the date is 2/10/2014, it still goes to True.., which is incorrect

When I change the End_Date to 3/1/2014, then it starts going to False

Am I unable to compare dates like this?  Is there a better way to compare dates?

Thank you,

Everyone's tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Date Comparison

I'm not sure I understand what you're doing, in order to give you an answer, however, I can tell you that Date objects, not Strings, are what you're going to want to work with when performing comparisons.

Date object values are also just a Long value for the number of milliseconds since Jan 1, 1970 at 00:00:00.000 AM.

It's key that you understand that it's the number of millisecond that it's holding.  Which explains why this is true today:  D[now] > D[2/6/2014].  Today being 2/6/2014 of course.  That because D[now] holds the current time the step is executed, whereas D[2/6/2014] is left to hold the time 00:00:00.000.  And no matter what time it is when the script executes, there's only a 1/86400000th of the day's time that they will be equal, which will make the conditional false.  Therefore, you would enter D[now] >= D[2/6/2014], which would be true for all 86400000 milliseconds of the day.  I, like you, would have expected that original condition to be false, because today is not after 2/6/2014; today is 2/6/2014.

The easiest way, in my opinion, to compare two dates, without consideration for their time values, is to reset the time values of both objects to the same value.

E.g.,

Set today = new Date()

Set today = new Date(today.getYear(), today.getMonth(), today.getDate())

Set start_date = new Date(2014 - 1900, 2, 6)

Set end_date = new Date(2014 - 1900, 2, 14)

If (today >= start_date && today <= end_date)

     True

          Goto Alt ToD

     False

          Goto ToD

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
2 REPLIES

Re: Date Comparison

I'm not sure I understand what you're doing, in order to give you an answer, however, I can tell you that Date objects, not Strings, are what you're going to want to work with when performing comparisons.

Date object values are also just a Long value for the number of milliseconds since Jan 1, 1970 at 00:00:00.000 AM.

It's key that you understand that it's the number of millisecond that it's holding.  Which explains why this is true today:  D[now] > D[2/6/2014].  Today being 2/6/2014 of course.  That because D[now] holds the current time the step is executed, whereas D[2/6/2014] is left to hold the time 00:00:00.000.  And no matter what time it is when the script executes, there's only a 1/86400000th of the day's time that they will be equal, which will make the conditional false.  Therefore, you would enter D[now] >= D[2/6/2014], which would be true for all 86400000 milliseconds of the day.  I, like you, would have expected that original condition to be false, because today is not after 2/6/2014; today is 2/6/2014.

The easiest way, in my opinion, to compare two dates, without consideration for their time values, is to reset the time values of both objects to the same value.

E.g.,

Set today = new Date()

Set today = new Date(today.getYear(), today.getMonth(), today.getDate())

Set start_date = new Date(2014 - 1900, 2, 6)

Set end_date = new Date(2014 - 1900, 2, 14)

If (today >= start_date && today <= end_date)

     True

          Goto Alt ToD

     False

          Goto ToD

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
New Member

Re: Date Comparison

Hi Anthony,

It's great to hear from you.

The whole reason I am comparing dates is for Daylight Savings Time.

I have a customer service team in the US and Mexico that connect to the same UCCX system.

DST for the US is on March 9th, Mexico's DST is April 9th.

So starting March 9th, the team based in Mexico would have incorrect Open hours by 1 hour for the entire month.

Regarding my script

If Today's Date was between DST_Starting date and DST_Ending date, it would go to the alternate hours (DST Active)

If it was outside the specified dates, it would go to regular hours (DST inactive)

I will try your recommended steps listed above

Thank you very much!

269
Views
0
Helpful
2
Replies
CreatePlease login to create content