Forum Discussion

mesg2anil's avatar
mesg2anil
Regular Contributor
14 years ago

Usage of Date and Time Log.SaveResultsAs

Hi...



I'm tying to use date and time stamp in the filename while saving it to a folder, the code is below. It is executing without any errors but it is not saving the file to the folder... Am I missing anything in the below code?




Sub SaveResults()


SaveResults()

Dim FileName


 



'Obtain the current date and time



NowValue = aqDateTime.Now                       ' using this line dint work so I converted date to string below


DatenTime = aqconvert.DateTimeToStr(NowValue)        'I thought it might work, this also dint work


 



'Write log file to folder



FileName = Project.ConfigPath &"\Log\Exported Log Report\Results" &DatenTime &".mht"


Log.SaveResultsAs Filename, 2


 End Sub

  • amit_deshpande's avatar
    amit_deshpande
    Occasional Contributor
    Hi,



    You may try aqConvert.DateTimeToFormatStr() function and specify the format of the string you desire.



    Thanks,



    Amit
  • mesg2anil's avatar
    mesg2anil
    Regular Contributor
    Hi Amit,



    As you suggested, I modified accordingly in the code shown below... but it is erroring out saying "Wrong number of arguments or invalid property assignment: 'aqConvert.DateTimeToFormatStr'" Any thing you see wrong in the below code?



    Sub SaveResults()

      Dim FileName

     

    'Obtain the current date and time

      NowValue = aqDateTime.Now

      DatenTime = aqConvert.DateTimeToFormatStr(NowValue)

     

    'Write log file to folder

      FileName = Project.ConfigPath &"\Log\Exported Log Report\" &DatenTime &"anil.mht"

      Log.SaveResultsAs Filename, 2

      Log.Message FileName

      Log.Message NowValue &" : " &DatenTime

     

    End Sub
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 3 rankChampion Level 3
    Hi Anil,



    DateTimeToFormatString() requires format string as the second parameter. See relevant help topic for more details and format specification.

  • Hi Anil,



    The reason for this is the fact that the date contains slashes, and the time contains colons that are not allowed in file names. To avoid them, use the aqConvert.DateTimeToFormatStr method, the second parameter of which is the date and time format without slashes and colons, for example:





      DatenTime = aqConvert.DateTimeToFormatStr(NowValue, "%m-%d-%Y %H_%M")









  • mesg2anil's avatar
    mesg2anil
    Regular Contributor
    David / Alexei / Amit,



    Did not think abt filename wont accept special characters...

    Thank you very much... :-) its working now...