Topic
  • 2 replies
  • Latest Post - ‏2013-07-12T13:02:44Z by JDD23
JDD23
JDD23
8 Posts

Pinned topic DifferenceDate

‏2013-07-11T12:28:54Z | date

I'm trying to calculate the difference (in days) between two dates from a CQ VB script:

 Dim firstDate
 Dim secondDate
 Dim result

 SetFieldValue "Date_Current", now ()
 firstDate = GetFieldValue ("Date_Threat").GetValue()
 secondDate = GetFieldValue ("Date_Current").GetValue()
 result = DateDiff(firstDate, secondDate)
 SetFieldValue("DaysToThreat"), result

CQ doesn't use DateDiff (in the script format that I'm using).

Is there a way I can calculate the difference in CQ? I'm a beginner.

Thanks in advance. JDD223

  • DonaldN
    DonaldN
    287 Posts
    ACCEPTED ANSWER

    Re: DifferenceDate

    ‏2013-07-12T01:00:19Z  

    What do you mean by saying "CQ doesn't use DateDiff"? Did you get an error?

    Essentially, do you realize that you are dealing with VBScript, not CQ? The way you used DateDiff() was incorrect, it should have been - result = DateDiff("d", firstDate, secondDate).

    More examples can be found here:

    http://www.w3schools.com/vbscript/func_datediff.asp

  • JDD23
    JDD23
    8 Posts
    ACCEPTED ANSWER

    Re: DifferenceDate

    ‏2013-07-12T13:02:44Z  
    • DonaldN
    • ‏2013-07-12T01:00:19Z

    What do you mean by saying "CQ doesn't use DateDiff"? Did you get an error?

    Essentially, do you realize that you are dealing with VBScript, not CQ? The way you used DateDiff() was incorrect, it should have been - result = DateDiff("d", firstDate, secondDate).

    More examples can be found here:

    http://www.w3schools.com/vbscript/func_datediff.asp

    Thanks again DonaldN.  I was under the impression that the CQ API does not accept all VBScript. 

    Since I'm not a programmer, I use a lot of trial and error and when the script doesn't perform I chalk it up to my inability to properly script (as I stated in my initial inquiry). 

    I had first tried a script example that did use "days" but that didn't work.  

    I searched for additional examples and found one that used "d" and calulates for business days.  My resultant script:

     Dim dates
     Dim datec
     Dim totald

     SetFieldValue "Date_Current", now ()
     dates = GetFieldValue("Date_Current").GetValue()
     datec = GetFieldValue("Date_Threat").GetValue()
     If dates = "" or datec = "" Then
     Else totald = DateDiff("d", dates, datec)- _
     DateDiff("ww", dates, datec, crSaturday)- _
     DateDiff("ww", dates, datec, crSunday)
     SetFieldValue "Days_Difference", totald
     End If

    Thanks DonaldN for your support to this forum and my questions!

  • DonaldN
    DonaldN
    287 Posts

    Re: DifferenceDate

    ‏2013-07-12T01:00:19Z  

    What do you mean by saying "CQ doesn't use DateDiff"? Did you get an error?

    Essentially, do you realize that you are dealing with VBScript, not CQ? The way you used DateDiff() was incorrect, it should have been - result = DateDiff("d", firstDate, secondDate).

    More examples can be found here:

    http://www.w3schools.com/vbscript/func_datediff.asp

  • JDD23
    JDD23
    8 Posts

    Re: DifferenceDate

    ‏2013-07-12T13:02:44Z  
    • DonaldN
    • ‏2013-07-12T01:00:19Z

    What do you mean by saying "CQ doesn't use DateDiff"? Did you get an error?

    Essentially, do you realize that you are dealing with VBScript, not CQ? The way you used DateDiff() was incorrect, it should have been - result = DateDiff("d", firstDate, secondDate).

    More examples can be found here:

    http://www.w3schools.com/vbscript/func_datediff.asp

    Thanks again DonaldN.  I was under the impression that the CQ API does not accept all VBScript. 

    Since I'm not a programmer, I use a lot of trial and error and when the script doesn't perform I chalk it up to my inability to properly script (as I stated in my initial inquiry). 

    I had first tried a script example that did use "days" but that didn't work.  

    I searched for additional examples and found one that used "d" and calulates for business days.  My resultant script:

     Dim dates
     Dim datec
     Dim totald

     SetFieldValue "Date_Current", now ()
     dates = GetFieldValue("Date_Current").GetValue()
     datec = GetFieldValue("Date_Threat").GetValue()
     If dates = "" or datec = "" Then
     Else totald = DateDiff("d", dates, datec)- _
     DateDiff("ww", dates, datec, crSaturday)- _
     DateDiff("ww", dates, datec, crSunday)
     SetFieldValue "Days_Difference", totald
     End If

    Thanks DonaldN for your support to this forum and my questions!