lr_save_datetime in Loadrunner with Examples

In this Loadrunner Tutorial you will learn about lr_save_datetime function. This is a very important function in LoadRunner. Let us understand why it is so important. The first thing we should understand is that LoadRunner stores date/time parameters locally on the system where LoadRunner has been installed. Now the script will work fine on the local system where the script has been created but when the same script is used or executed on any other system, it could cause an issue because date-time format supported by another system could be different. So to handle this scenario, we use this function. It is recommended that we use this function lr_save_datetime function is used to save date or time values in the string format which can be used and we can use the same script on various systems without making it system dependent. In short, we can say that this function is science assigns Assigns the current date and time to a parameter.

Let us see the syntax of the function as given below

void lr_save_datetime( const char *format, int offset, const char *name );

We can see that this function does not return any value. Let us see the parameter that is taken as input/ arguments for this function. It is given below.

format-  It represents the format of the retrieved date/time information.

offset high on    Offset may be defined as deviation from the current date and time, using the constants: DATE_NOW, TIME_NOW, ONE_DAY, ONE_HOUR, ONE_MIN. For example, TIME_NOW + ONE_HOUR.

name-   The name of the parameter is where we store the date/time information.

We will see in the live example where we will be using this function in this format.  Let us see the sample code below to understand it better.



//function is saving current date time


//printing current date time in the output log window of LoadRunner


//saving day time of next day


//printing same date, time of next day in the output log window of LoadRunner


//saving current date and time using TIME_NOW


//printing current date and time


//saving current date time after one hour


//printing date time after one hour


                return 0;


Let us see how it looks in the LoadRunner window. The screenshot is given below.

Let us see the output given below.

Maximum number of concurrent connections per server: 6           [MsgId: MMSG-26989]

Starting action Action.

Action.c(4): 4/9/2020 4:48:05 PM

Action.c(6): 4/10/2020 4:48:05 PM

Action.c(8): 4/9/2020 4:48:05 PM

Action.c(10): 4/9/2020 5:48:05 PM

Ending action Action.

Ending iteration 1.

Ending Vuser…

Let us see the output log window of the LoadRunner after executing the code. The highlighted section shows the output value of the code.

Overall, we can say that it is a very useful function to work with DateTime in LoadRunner and also makes date-time format universally compatible with all the systems irrespective of the system where the script has been developed. This function has to be used wisely for the productive result during the creation of performance script using LoadRunner.

For more Loadrunner Functions with examples read this page.

1 thought on “lr_save_datetime in Loadrunner with Examples”

Leave a Comment