Forum Discussion

tmahender12's avatar
tmahender12
Frequent Contributor
8 years ago

Replace Year in a Date

HI,

 

I have a Date 02/09/2016, i need to replace 2016 with 2013, is there any direct method in the TestComplete?

 

thanks

Mahender

9 Replies

  • Hi, convert it to string and try bellow code 

    string.replace(searchvalue,newvalue) 

    works for JS

     

     

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      The replace method is correct... however, I don't think you can do it directly with aqDateTime(Now) as that doesn't return a string but a DateTime value which is a numeric value. What you would have to do is take what aqDateTime returns and run it through aqConvert.DateTimeToStr or aqConvert.DateTimeToFormatStr in order to put the date into a string format.  Then you can do the necessary string replace call.

      • Kostja's avatar
        Kostja
        Contributor

        Hi,

         

        don't want to spam here, but just for the protocol (and the code was only as an example) :) -->

  • baxatob's avatar
    baxatob
    Community Hero

     

    initial_date = '9/2/2016'
     
    new_date = aqDateTime.AddMonths(initial_date, -36) # ==> 9/2/2013

     

    It uses system format by default. If you need another date format, use aqConvert.DateTimeToFormatStr method.