Sunday, August 25, 2019

Removing leading zero from the date in LoadRunner - 06/12/2020 to 6/12/2020

How to change 06/12/2020 to 6/12/2020? here is the code..

Action()
{
char month[10],day[10],year[10],startingDate[10]; //Declaration the variables here
int nonzeroday, nonzeromonth;

strcpy(startingDate,"");

lr_save_datetime("Today's Date is: %m/%d/%Y",DATE_NOW,"normal_date"); //Capturing Today's date and writing it to the Log

lr_output_message(lr_eval_string("{normal_date}"));

lr_save_datetime("%m",DATE_NOW,"month"); //Capturing month of date to a parameter
lr_save_datetime("%d",DATE_NOW,"day");  //Capturing day of date to a parameter
lr_save_datetime("%Y",DATE_NOW,"year");//Capturing year of date to a parameter

nonzeromonth=atoi(lr_eval_string("{month}")); // This it to remove zero from the month value
lr_save_int(nonzeromonth,"month");

nonzeroday=atoi(lr_eval_string("{day}"));  // This it to remove zero from the day value
lr_save_int(nonzeroday,"day");


strcat(startingDate,lr_eval_string("{month}")); //Concatenating  date with '/' to create a date
strcat(startingDate,"/");
strcat(startingDate,lr_eval_string("{day}"));
strcat(startingDate,"/");
strcat(startingDate,lr_eval_string("{year}"));


lr_save_string(startingDate,"p_startingDate");
lr_output_message("Corrected Date is: %s", lr_eval_string("{p_startingDate}"));

return 0;
}

Then your final output will be:

Action.c(34): Today's Date is: 06/12/2020
Action.c(65): Corrected Date is: 6/12/2020

No comments: