Load Runner Function - How to get current system time

This function is developed to usein Mercury Load Runner peformance tool.

This main use of this functions to return the current system time at any given

point of time while load runner script is running.This functiona can be used to

report transaction times , script starti time and end time.

 

long get_secs_since_midnight(void)
{
 char  * curr_hr;         /* pointer to a parameter with current clock hr   */       
 char  * curr_min;       /* pointer to a parameter with current clock min*/
 char  * curr_sec;       /* pointer to a parameter with current clock sec */
 long  current_time,     /* current number of seconds since midnight     */
       hr_secs,              /* current hour converted to secs                     */
       min_secs,            /* current minutes converted to secs                */
       secs_secs;           /* current number of seconds                          */


    curr_hr   = lr_eval_string("{current_hr}>");
    curr_min  = lr_eval_string("{current_min}");
    curr_sec  = lr_eval_string("{current_sec}");

 hr_secs   = (atoi(curr_hr)) * 60 * 60;
    min_secs  = (atoi(curr_min)) * 60;
    secs_secs = atoi(curr_sec);
   
 current_time = hr_secs + min_secs + secs_secs;

 return(current_time);
}

Showing Answers 1 - 11 of 11 Answers

pratheepa

  • Jan 16th, 2006
 

hi,

just two lines are enough for getting current time.

lr_save_datetime("Today is %H %M %S", DATE_NOW, "curr_time");
lr_output_message(lr_eval_string("{curr_time}"));

  Was this answer useful?  Yes

You can utilise the parameter value for "Date/Time" where Vugen can extract the date for you depending on the format you want.  This is much simpler in writing codes.

-papayamilkshake 

  Was this answer useful?  Yes

soori.p

  • Jun 3rd, 2008
 

typedef long time_t;

Action()

{

     time_t t; 

lr_message("Time in seconds since 1/1/70: %ldn", time(&t));

     lr_message("Formatted time and date: %s", ctime(&t));

     return 0;

}

  Was this answer useful?  Yes

Monika

  • Dec 5th, 2014
 

%H behaves exactly like %I. for eg:

lr_save_datetime("%H%M%S", TIME_NOW + 5*ONE_HOUR, "curr_time");

should give output as 141500 (assuming Current time is 09:15:00) but the value of curr_time comes as 021500

  Was this answer useful?  Yes

JonyGreen

  • Sep 24th, 2015
 

I am not a developer, I always use the free online timestamp generator to get current UNIX timestamp.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions