Forum Discussion

DCat1223's avatar
DCat1223
Frequent Contributor
10 years ago

Custom Date expression / format help

Good afternoon.  I need to create a custom date expression that basically inputs the birthdate of somebody who is 10 years old.  So this expression needs to take today's date and subtract 10 years, formatted mm/dd/yyyy and input that date into a text box formatted mm/dd/yyyy .

 

What is the correct expression to use with the Expression Editor?  I have an attached screenshot. 

 

If there is a better way to do this, please advise. 

 

Thank you in advance.

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi DCat1223,

     

    You can use the aqDateTime and aqConvert objects to build the needed expression.

     

    aqDateTime.Today() returns today's date.
    aqDateTime.AddMonths(date, -120) subtracts 10 years (120 months) from a date.
    aqConvert.DateTimeToFormatStr(date, "%m/%d/%Y") formats a date as "mm/dd/yyyy".

     

    With all of these combined, your expression would be:

    aqConvert.DateTimeToFormatStr(aqDateTime.AddMonths(aqDateTime.Today(), -120), "%m/%d/%Y")
    • DCat1223's avatar
      DCat1223
      Frequent Contributor

      Thank you so much, Helen!  That was it!  I really appreciate your help! 

       

      Dave C.