Forum Discussion

prateek_goyal's avatar
prateek_goyal
Occasional Contributor
11 years ago

How to get corresponding year

I have a problem regarding how to get the corresponding year.In this we need to verify that Datagrid contains Column <CurrentMonth -1>/<Corresponding Year> so my question is how can we calculate the Corresponding year if CurrentMonth is "January"  so if January - 1 = December than corresponding month should be 2013.



DATAGRID: (COLUMN["<Current Month - 1>/<Corresponding Year>"] , COLUMN["<Current Month>/<Corresponding Year>"] , COLUMN["<Current Month + 1>/<Corresponding Year>"] , COLUMN["<Current Month + 2>/<Corresponding Year>"]))



Can anyone please suggest how to calculate the corresponding year of the above step.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi,



    To say the truth, I don't quite understand what the problem is...





    Sub TestAddMonth

      Dim i

      Dim dtNow



      dtNow = aqDateTime.Now

      For i = -12 To 12

        Call Log.Message(aqConvert.DateTimeToFormatStr(aqDateTime.AddMonths(dtNow, i), "%#m/%Y"))

      Next

    End Sub








    Does the above help?


  • jose_pita's avatar
    jose_pita
    Super Contributor




    function date(){


      var currentDate = new Date()


      var day = currentDate.getDate()


      var month = currentDate.getMonth()+1


      if(day<=9)


        day="0"+day;


      if(month<=9)


        month="0"+month;


      var year = currentDate.getFullYear()


      Project.Variables.todaysDate=day + "." + month + "." + year;


      Project.Variables.begginingOfTheYear="01.01." + year;


      Project.Variables.endOfTheYear="30.12." + year;


      Project.Variables.oneYearAgo=day + "." + month + "." + (year-1);


      Project.Variables.oneYearMore=day + "." + month + "." + (year+1);


      if( month>=2)


      {  


        if(month<=10)


        {


          Project.Variables.oneMonthMore=day + ".0" + (month-1) + "." + year;


       //   Log.Message("oneMonthMore: "+Project.Variables.oneMonthMore);


        }


        else


        {


          Project.Variables.oneMonthMore=day + "." + (month-1) + "." + year;


      //    Log.Message("oneMonthMore: "+Project.Variables.oneMonthMore);


        }


      }


      else


      {


        Project.Variables.oneMonthMore=day + ". 12 ." + (year-1);


     //   Log.Message("January oneMonthMore: "+Project.Variables.oneMonthMore);


      }


      if(day===1)


      {


        if(month===1)


          Project.Variables.oneMonthMoreAndOneDay = 30+ "." + 12+ "."+ (year-1);


        Project.Variables.oneMonthMoreAndOneDay = 30+ "." + (month-1)+ "."+ year;


      }


      else


      {


        if(month<=10)


        Project.Variables.oneMonthMoreAndOneDay = (day -1)+ ".0" + (month-1)+ "."+ year;


      }


    }


     


    function getDateX_days_Before(n)


    {


      var DateTimeString;


      


        DateTimeString = aqDateTime.Today();  


        DataTemp = aqDateTime.AddDays(DateTimeString, -n);    


        DataTemp = aqConvert.DateTimeToFormatStr(DataTemp, "%d.%m.%Y");


     


        Log.Message(DataTemp);


        return DataTemp;  


    }


     


    function getDateX_days_After(n)


    {


        var DateTimeString;


      


        DateTimeString = aqDateTime.Today();  


        DataTemp = aqDateTime.AddDays(DateTimeString, +n);    


        DataTemp = aqConvert.DateTimeToFormatStr(DataTemp, "%d.%m.%Y");


     


        Log.Message(DataTemp);


        return DataTemp;  


    }




  • prateek_goyal's avatar
    prateek_goyal
    Occasional Contributor
    Hi Alexei,



    I have tried this method too "aqDateTime.AddMethod" but i need to verify that DataGrid Contains Column <CurrentMonth-1>/<CorrespondingYear>



    Please check the screenshot with the attachments.

    DataGrid Contains Column 2/2014 

    So here we need to validate that column which is coming dynamically.

    If we run this test case in January 2015 then it will be failed because the

    Column Value <CurrentMonth>-1 will be coming December than our year must be the same as 2015 if we using aqDateTime.Today(%y) to calculate current year . But here we need to verify that if month is less than January than year must be the corresponding to it.