Vugen: Manipulate The Date

When using the lr_save_datetime function, you may want to advance or decrement more than one day, you have to multiply by the number of days.

Example code:

// Display Current Date Only
 lr_save_datetime("%m/%d/%Y",DATE_NOW,"Currdate");
 lr_output_message("Current Date: %s",lr_eval_string("{Currdate}"));
 
// Subtract 30 days from current date
 lr_save_datetime("%m/%d/%Y", DATE_NOW - (ONE_DAY*30), "Startdate");
 lr_output_message("Previous 30 Days: %s",lr_eval_string("{Startdate}"));
 
// Advance 30 days from current date
 lr_save_datetime("%m/%d/%Y", DATE_NOW + (ONE_DAY*30), "Startdate1");
 lr_output_message("Advance 30 Days: %s",lr_eval_string("{Startdate1}"));

As of LoadRunner version 7.8 and higher, there is an offset function in the date/time parameter properties box that let’s you set the date back or forwards by as many hours/minutes/seconds as you want.

What's Next?

Did you enjoy this article? Help spread the word by sharing:

Join the Northway Navigator Club today and get access to restricted content including our best tips and tricks. Membership is free! You will also receive free email updates by registering.

Engage in the conversation and leave a comment:

Scott Moore

About Scott Moore (153 articles)

With over 20 years of IT experience with various platforms and technologies, Scott has tested some of the largest applications and infrastructures in the world. He is a Certified Instructor and Certified Product Consultant in HP’s LoadRunner and Performance Center products. He currently holds HP certifications for ASE, ASC, and CI. A thought leader in the APM space, he speaks regularly at IT conferences and events



  • http://www.facebook.com/anthonylyski Anthony Lyski

    That is great for regular time, although it is something that you can do with the parameter function like mentioned. There are additional offsets that you can use like… ONE_HOUR, ONE_MIN, ONE_SEC etc..
    It is a little more difficult once you start working with Unix time. Below is a good example:

    char utime[16];

    //Current Unix time

    sprintf(utime, “%ld”, (long)time(NULL));

    lr_save_string(utime, “pUnixTime”);

    lr_message(“UnixTime = %s”, lr_eval_string(“{pUnixTime}”));

    //Unix Time Plus 30 days

    sprintf(utime, “%ld”, (long)time(NULL) + (ONE_DAY*30));

    lr_save_string(utime, “pUnixTime”);

    lr_message(“UnixTime + 30 days = %s”,
    lr_eval_string(“{pUnixTime}”));

    //Unix Time Minus 30 days

    sprintf(utime, “%ld”, (long)time(NULL) – (ONE_DAY*30));

    lr_save_string(utime, “pUnixTime”);

    lr_message(“UnixTime – 30 days = %s”,
    lr_eval_string(“{pUnixTime}”));

    lr_message(“ONE_DAY = %ld”, ONE_DAY);

    lr_message(“ONE_HOUR = %ld”, ONE_HOUR);

    lr_message(“ONE_MIN = %ld”, ONE_MIN);

    lr_message(“one sec is just 1 = %ld”, 1);