Resource icon

Loadrunner Function to write current system Time 2017-12-05

No permission to download
  • perf-test.com need your contributions to build up a strong repository of performance engineering resources.

This main use of this functions to return the current system time at any given point of time while loadrunner script is running.This function can be used to report transaction times , script starting time and end time.

Attached is a sample script for demo purpose.

Please share more methods to work with date time functions on loadrunner and support this community.

Code:
Action()
{
   
    lr_save_datetime("Today is %H %M %S", DATE_NOW, "curr_time");
    lr_output_message(lr_eval_string("{curr_time}"));
   
    return 0;
}

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);

}

Output of above code:

upload_2017-12-7_23-11-31.png



Other Example: lr_save_datetime

In the following example, lr_save_datetime retrieves tomorrow's date.

lr_save_datetime("Tomorrow is %B %d %Y", DATE_NOW + ONE_DAY, "next");
lr_output_message(lr_eval_string("{next}"));
// Output: Action.c(4): Tomorrow is November 18 2014

These examples show the effect of formatting:

lr_save_datetime("%Y-%m-%d", DATE_NOW, "dateReceived");
lr_output_message(lr_eval_string("{dateReceived}"));
// Output: Action.c(7): 2014-11-17

lr_save_datetime("%m/%d/%Y %H:%M", DATE_NOW, "currDateTime");
lr_output_message(lr_eval_string("{currDateTime}"));
// Output: Action.c(10): 11/17/2014 15:14
Author
admin
Downloads
1
Views
95
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from admin