Removing leading zero from the date in LoadRunner
Below few lines shows how to remove leading zero from date. Like
We have a date as 03/26/2014
The output should be 3/26/2014
If the date is 03/01/2014
The output should be 3/1/2014
Solution:
Action()
{
//Declaration of variables
char month[10],day[10],year[10],startDate[10];
int nonzeroday, nonzeromonth;
//nullifying the startDate
strcpy(startDate,"");
//Capturing Today's date and output to Log
lr_save_datetime("Today's Date is: %m/%d/%Y",DATE_NOW,"normal_date");
lr_output_message(lr_eval_string("{normal_date}"));
//Capturing each part of date to a parameter
lr_save_datetime("%m",DATE_NOW,"month");
lr_save_datetime("%d",DATE_NOW,"day");
lr_save_datetime("%Y",DATE_NOW,"year");
//To remove zero from month
nonzeromonth=atoi(lr_eval_string("{month}"));
lr_save_int(nonzeromonth,"month");
//To remove zero from day
nonzeroday=atoi(lr_eval_string("{day}"));
lr_save_int(nonzeroday,"day");
//Creating a date using concatenation of date with '/'
strcat(startDate,lr_eval_string("{month}"));
strcat(startDate,"/");
strcat(startDate,lr_eval_string("{day}"));
strcat(startDate,"/");
strcat(startDate,lr_eval_string("{year}"));
//Save the date and send to output
lr_save_string(startDate,"p_startdate");
lr_output_message("Date is: %s", lr_eval_string("{p_startdate}"));
return 0;
}
Output:
Action.c(12): Today's Date is: 03/26/2014
Action.c(36): Date is: 3/26/2014
If date is below:
lr_save_datetime("Today's Date is: %m/%d/%Y",DATE_NOW+ONE_DAY*6,"normal_date");
Output:
Action.c(12): Today's Date is: 04/01/2014
Action.c(36): Date is: 4/1/2014
Comments
Post a Comment