Forum Discussion

royd's avatar
royd
Regular Contributor
7 years ago
Solved

aqDateTime.Today() - date format problem.

I am getting an error while creating a new patient. The patient admission date is a month/two into the future. The admission date format calls for mm/dd/yyyy. aqDateTime.Today() produces mm/dd/yy + time. 

 

How can I produce four digit year without the time? I need just 06/24/2017 (without the time).

 

Here is my code (JScript):

 

  var currentDate = aqDateTime.Today();
  var dOAdmission = aqDateTime.AddMonths(currentDate, 2);
  Log.Message("Today is" + aqConvert.DateTimeToFormatStr(dOAdmission, " %m/%d/%y"));

Output is logged as: "Admission date is 06/24/17 6:57:23 Normal".

 

Thanks.

10 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    If you want 4 digit year then you have to provide %Y instead of %y.

     

    var currentDate = aqDateTime.Today();
    var dOAdmission = aqDateTime.AddMonths(currentDate, 2);
    Log.Message("Today is" + aqConvert.DateTimeToFormatStr(dOAdmission, " %m/%d/%Y"));

    Output[highlighted in Green] is Today is 06/24/2017 17:24:39 Normal

     

    And for more specifiers. https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/date-and-time-format-specifiers.html

    • royd's avatar
      royd
      Regular Contributor

      Hi Shankar

       

      Thanks for your reply, the funny thing is I tried %yy thinking that will add four digits (before posting here), I did not see any documentation on y and Y! It does work! Thanks for the link to "Date and Time Format Specifiers".

       

      But now I have a different issue! The date is 06/24/2017, but TestComplete is entering  06/24/201 ! I have already sent an email to the Devs, thinking it may be an issue on their end (not heard from them yet). Could it be an issue with TestComplete, how it is interacting with the field? See the screen capture, please.

       

       

      robert, Thanks for pointing out my oversight! :) I know when coping log message, it does copy the time stamp! Going through documentation, found out Today method does not contain time stamp, so when I time (when pasted the log), and did not realize that it came from log, not part of actual date!

       

      Any idea, why the last digit is seen as 11th. digit by TestComplete and truncated?

       

      Thank you both for your valuable time, I really appreciate it.

       

      Dave

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        See my commentary in the screenshot

         

         

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    BTW, the time that you pasted in is not part of the message itself, it's part of the log indicating when the Log record was entered.  As shankar_r, what's highlighted in green is the actual output of your log.