top of page

Lr_save_datetime Function In Loadrunner With Examples

Lr_save_datetime Function In Loadrunner With Examples

By Sam Z // Friday, May 23, 2014

By using this function we can save the current date, time, day, hour, and minute into parameter. We have the following predefined constants that we can use with the function: DATE_NOW, TIME_NOW, ONE_DAY, ONE_HOUR, ONE_MIN.

Example 1:

Action() { lr_save_datetime("%c",DATE_NOW,"Date"); lr_output_message(lr_eval_string("{Date}")); lr_save_datetime("%c",DATE_NOW+ONE_DAY,"OneDayAdvanceDate"); lr_output_message(lr_eval_string("{OneDayAdvanceDate}")); lr_save_datetime("%c",TIME_NOW,"TimeNow"); lr_output_message(lr_eval_string("{TimeNow}")); lr_save_datetime("%c",TIME_NOW+ONE_HOUR,"TimeNowPlusOneHour"); lr_output_message(lr_eval_string("{TimeNowPlusOneHour}")); return 0; }

Output:

Starting action Action.

Action.c(4): 5/22/2014 12:22:14 PM

Action.c(6): 5/23/2014 12:22:14 PM

Action.c(8): 5/22/2014 1:22:14 PM

Action.c(10): 5/22/2014 1:22:14 PM

Ending action Action.

Different Date Formats Table:

Code

Date Format

Description

%a

Fri

It gives abbreviated name of a day

%A

Friday

It gives full name of a day

%b

Jun

It gives abbreviated name of month

%B

May

It gives full name of the month

%c

5/23/2014 10:55

Date and Time Stamp

%d

23

Today's Date

%H

10

It gives hour with 24 hours format

%I

10

It gives with 12 hour format

%j

143

It gives number of day in a year

%m

5

Month of the year in number format

%M

55

It gives present minute

%p

AM

It Gives AM/PM

%S

35

It gives seconds

%U

20

week number of a year with first Sunday in a year as 01

%w

5

Day of the week with Sunday as zero(0)

%W

20

It gives week no the year with first Monday in a year as 01

%x

5/23/2014

It gives Today's Date

%X

10:55:35 AM

It gives time now

%y

14

It gives year without century

%Y

2014

It gives year with century

%Z

India Standard Time

It gives time zone abbreviation

%%

%

it gives % output in your date format

Example 2:

lr_save_datetime("Today is (with abrreviated name) %a",DATE_NOW,"WeekDay"); lr_output_message(lr_eval_string("{WeekDay}"));

Output: Today is (with abbreviated name) Fri

Example 3:

lr_save_datetime("Today is (with full name) %A",DATE_NOW,"WeekDay"); lr_output_message(lr_eval_string("{WeekDay}")); Output: Today is (with full name) Friday

Example 4:

lr_save_datetime("This month is (with abbreviated name) %b",DATE_NOW+ONE_DAY*30,"Month"); lr_output_message(lr_eval_string("{Month}")); Output: This month is (with abbreviated name) Jun

Example 5:

lr_save_datetime("This month is (with full name) %B",DATE_NOW+ONE_DAY*30,"Month"); lr_output_message(lr_eval_string("{Month}"));

Output: This month is (with full name) June

Example 6:

lr_save_datetime("%c Date with time stamp",DATE_NOW,"DateAndTimeStamp"); lr_output_message(lr_eval_string("{DateAndTimeStamp}")); Output: 5/23/2014 11:56:18 AM Date with time stamp

Example 7:

lr_save_datetime("Only Todays Date %d",DATE_NOW,"TodayDate"); lr_output_message(lr_eval_string("{TodayDate}")); Output: Only Todays Date 23

Example 8:

lr_save_datetime("Gives 24 Hours %H",DATE_NOW,"24_Hours"); lr_output_message(lr_eval_string("{24_Hours}"));

Output: Gives 24 Hours 11

Example 9:

lr_save_datetime("Gives 12 Hours %I",DATE_NOW,"12_hours"); lr_output_message(lr_eval_string("{WeekDay}"));

Output: Today is (with full name) Friday

Example 10:

lr_save_datetime("It gives number of day in a year %j",DATE_NOW,"TodayNumber"); lr_output_message(lr_eval_string("{TodayNumber}"));

Output: It gives number of day in a year 143

Example 11:

lr_save_datetime("Month in number format %m",DATE_NOW,"MonthInNo"); lr_output_message(lr_eval_string("{MonthInNo}")); Output: Month in number format 05

Example 12:

lr_save_datetime("Gives present minute %M",DATE_NOW,"Minute"); lr_output_message(lr_eval_string("{Minute}"));

Output: Gives present minute 56

Example 13:

lr_save_datetime("Gives AM/PM %p",DATE_NOW,"AM_PM"); lr_output_message(lr_eval_string("{AM_PM}"));

Output: Gives AM/PM AM

Example 14:

lr_save_datetime("Gives Seconds %S",DATE_NOW,"Seconds"); lr_output_message(lr_eval_string("{Seconds}"));

Output: Gives Seconds 18

Example 15:

lr_save_datetime("Gives week no of the year (with Sunday as 01) %U",DATE_NOW,"WeekNo"); lr_output_message(lr_eval_string("{WeekNo}"));

Output: Gives week no of the year (with Sunday as 01) 20

Example 16:

lr_save_datetime("Day of the week with sunday as(zero) %w",DATE_NOW,"DayNo"); lr_output_message(lr_eval_string("{DayNo}"));

Output: Day of the week with sunday as(zero) 5

Example 17:

lr_save_datetime("Week No of the Year (with Monday as 01) %W",DATE_NOW,"WeekNo"); lr_output_message(lr_eval_string("{WeekNo}"));

Output: Week No of the Year (with Monday as 01) 20

Example 18:

lr_save_datetime("It gives Todays Date %x",DATE_NOW,"TodaysDate"); lr_output_message(lr_eval_string("{TodaysDate}"));

Output: It gives Todays Date 5/23/2014

Example 19:

lr_save_datetime("It gives time now %X",DATE_NOW,"TimeNow"); lr_output_message(lr_eval_string("{TimeNow}"));

Output: It gives time now 11:56:18 AM

Example 20:

lr_save_datetime("Year without centuary %y",DATE_NOW,"YearWOCentuary"); lr_output_message(lr_eval_string("{YearWOCentuary}"));

Output: Year without centuary 14

Example 21:

lr_save_datetime("Year with centuary %Y",DATE_NOW,"YearWCentuary"); lr_output_message(lr_eval_string("{YearWCentuary}"));

Output: Year with centuary 2014

Example 22:

lr_save_datetime("Abbreviation of time zone %Z",DATE_NOW,"TimeZoneAbbr"); lr_output_message(lr_eval_string("{TimeZoneAbbr}"));

Output: Abbreviation of time zone India Standard Time

Example 23:

lr_save_datetime("Today is %d%%%Y", DATE_NOW, "TodayDate"); lr_output_message(lr_eval_string("{TodayDate}"));

Output: (with parameter substitution in Extended Log)

Saving Parameter "TodayDate = Today is 23%2014". Notify: Parameter Substitution: parameter "TodayDate" = "Today is 23%2014" Today is 23 (Seems here the lr_eval_string is removing the embedded parameters - You can ignore it - Not Sure What Happening in the background)


bottom of page