Forum Discussion

makula's avatar
makula
Occasional Contributor
11 years ago

aqDateTime.Time() method returning accurate time but wrong date(Dec 30 Sat 1899)

Hi,

I am using TestComplete 9, and code snippet (using Jscript) that i used is to get current time is aqDateTime.Time(). But the result is as 

             "Sat Dec 3- 00:47:43 UTC +0530 1899"

but according to the index help it shows that use Time method to get current time. Could any one please help me out of this.



thanks!!



5 Replies

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi Mamatha, the behaviour you are describing is consistent with the documentation for the aqDateTime.Time() method, i.e


     


    "In JScript or DelphiScript, if you try to output the time returned by the Time method as a string, conversion takes place and the time is outputted in the day/month/date/time/year format. For example, this occurs if you use the following code to post the current time to the test log:"


     


    function Test()


    {


      Log.Message("Time is" + aqDateTime.Time());


    }


     


    "To avoid such a conversion, you need to explicity specify the format in which time should be displayed. For example, you can use the following code:"


     


    function Test()


    {


      Log.Message("Time is" + aqConvert.DateTimeToFormatStr(aqDateTime.Time(), "%H:%M:%S"));


    }


     


    If you wish to get an accurate date/time value, you should use the aqDate.Now() method


     


    Regards,


    Phil Baird

  • marin's avatar
    marin
    Frequent Contributor
    Hello Mamatha,



    according to TC manual this is the cause:

    Here the description of method:



    "...

    Declaration



    aqConvert.DateTimeToStr(D)

















    D

    [in]

    Required

    Date/Time

     

    Result

    String



    The method has the following parameter:





    D




    The date/time value to be converted to a string. If the date part of the value is missing, it is assumed to be the “zero date”, December 30, 1899. If the time part is missing, it is not included in the resulting string.

    ..."



    As you are using aqDateTime.Time() to fetch the time value only, there will be only time part there (see attached image and look in manual of description of aqDateTime.Time()).

    This is why it will be the 30/12/1899 assumed as "zero date" for conversion method aqConvert.DateTimeToStr().



    Hope this helps,



    Regards,



    Marin





  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Apologies, that should read aqDateTime.Now() not aqDate.Now()


     


    Phil

  • makula's avatar
    makula
    Occasional Contributor
    Hi Phil,

    I know the method you have mentioned to format the date/time to string. The thing is when we use aqConvert.DateTimeToStr(aqDateTime.Today() )it returns current date, only date is logged in log file without any explicit format [aqConvert.DateTimeToFormatStr(aqDateTime.Today(), "%m/%d/%y"));] but when we use  aqConvert.DateTimeToStr(aqDateTime.Time()) why only time is not returned. Hope you got my point. Hope the image attached gives you info about what am I asking.



    the Jscript used is :


      Log.Message('Current date and time is      '+aqConvert.DateTimeToStr(aqDateTime.Now()));


      Log.Message('Current time only             '+aqConvert.DateTimeToStr(aqDateTime.Time()));


      Log.Message('Current date only             '+aqConvert.DateTimeToStr(aqDateTime.Today()));







    Thanks,

    Mamatha