C Function – Add five minutes to current time

I needed to write a function which added five minutes to the current time in a LoadRunner script. This allowed a script to simulate appointment bookings for a web application.

The function could be modified to add more or less time, the clever bit was making sure that it handled the last few minutes of an hour properly.

For example.
13:56 + 5 minutes = 14:01

The function handles this by converting the 13 and the 56 into integers, doing the necessary sums and then converting the results back into strings which LoadRunner can use.

When the integers are converted back to strings, single digit number are displayed correctly e.g. 01,02,03 etc. rather than 1,2,3.

The function will not work in the last five minutes of the day because I haven’t added a function to add five minutes to 23:56 to get 00:01. (If you’re running tests this late, don’t use this function).



int iCurrentHour;

int iCurrentMinute;

int iTotalMinutes;

int iNextHour;

int iNextMinute;

char sTimeNow[6];

char sTimeInFiveMins[6];

char sTemporaryTimeValue[3];

char sCharCurrentHour[3];

char sCharCurrentMinute[3];

char sCharNextHour[3];

char sCharNextMinute[3];

lr_save_datetime(“%H”, TIME_NOW , “sCurrentHour”);

lr_save_datetime(“%M”, TIME_NOW , “sCurrentMinute”);

// Uncomment these next two lines if you need to test the function using alternative times.

// lr_save_string(“12”, “sCurrentHour”);

// lr_save_string(“58”, “sCurrentMinute”);

//Convert Hour and Minute into iHour and iMinute (integers)

//Convert Hours into Minutes

iCurrentHour = atoi(lr_eval_string(“{sCurrentHour}”));

iCurrentMinute = atoi(lr_eval_string(“{sCurrentMinute}”));

//Add 5 minutes to the current time



//If after the 54th minute in the hour, add 1 hour to the “hour” time and take 55 minutes off the “minute” time

if (iCurrentMinute>54)





//Convert integers back into strings

//The “if” statements make sure that the times are formatted correctly after the maths has been done.

//e.g. Five past One in the morning is 01:05, instead of 1:5


if (strlen(lr_eval_string(“{sCurrentHour}”))<2)


strcpy(sTemporaryTimeValue, “0”);

strcat(sTemporaryTimeValue, lr_eval_string(“{sCurrentHour}”));

sprintf(sCharCurrentHour, “%s”, sTemporaryTimeValue);

lr_save_string(sTemporaryTimeValue, “sCurrentHour”);



if (strlen(lr_eval_string(“{sCurrentMinute}”))<2)


strcpy(sTemporaryTimeValue, “0”);

strcat(sTemporaryTimeValue, lr_eval_string(“{sCurrentMinute}”));

sprintf(sCharCurrentMinute, “%s”, sTemporaryTimeValue);

lr_save_string(sTemporaryTimeValue, “sCurrentMinute”);



if (strlen(lr_eval_string(“{sNextHour}”))<2)


strcpy(sTemporaryTimeValue, “0”);

strcat(sTemporaryTimeValue, lr_eval_string(“{sNextHour}”));

sprintf(sCharNextHour, “%s”, sTemporaryTimeValue);

lr_save_string(sTemporaryTimeValue, “sNextHour”);



if (strlen(lr_eval_string(“{sNextMinute}”))<2)


strcpy(sTemporaryTimeValue, “0”);

strcat(sTemporaryTimeValue, lr_eval_string(“{sNextMinute}”));

sprintf(sCharNextMinute, “%s”, sTemporaryTimeValue);

lr_save_string(sTemporaryTimeValue, “sNextMinute”);


lr_output_message(“The current time is %s:%s”,lr_eval_string(“{sCurrentHour}”),lr_eval_string(“{sCurrentMinute}”));

lr_output_message(“The time in 5 minutes will be %s:%s”,lr_eval_string(“{sNextHour}”),lr_eval_string(“{sNextMinute}”));

return 0;



About me

I am an experienced IT consultant with over fourteen years of experience gained in a number of technical roles, including more than 10 years experience as an application performance tester and test manager. I specialise in a number of technical disciplines including Microsoft server operating systems and HP testing tools (LoadRunner and QTP). I am an excellent communicator with both technical and business audiences.

I left HBOS (Lloyds Banking Group) in November 2009 after six years working as a senior performance tester and test manager. During my time at HBOS, I was responsible for performance testing customer facing web-sites as well as key internal and core banking applications using LoadRunner. I managed a team responsible for the performance testing of the HBOS Faster Payments system using Iliad FasTest. This was, and remains, the most ambitious test project ever undertaken by HBOS plc. As well as training and mentoring my colleagues in the performance test team, I acted as a technical advisor on Performance Center, LoadRunner and HP Diagnostics software throughout Lloyds Banking Group.

I take an active role in the UK and worldwide testing community. As well as being co-leader of the UK HP Software user group,VIVIT, I have been invited to sit on Vivit’s Board of Directors to help develop Vivit services for members throughout Europe. I have been called to speak at UK and worldwide conferences by HP and by the British Computer Society at their SIGIST testing conferences on the subject of performance testing and “building performance test centres of excellence”.

After leaving HBOS, I created my own company “Richard Bishop IT Ltd” and worked through 2010 and early 2011 working for a client in London two days per week and remotely from home. I took on a new role at Intechnica in Manchester in May 2011. Intechnica designs, develops and tests high performance web applications, specialising in cloud application development and testing.