Skip to main content

lr_save_datetime function in loadrunner with examples

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)
     

Comments

  1. the out put will be formated as folowing

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

    thanks for ur examples they are really helpful

    ReplyDelete
  2. thanks for your functions they are really helpful, in the ex.23 we could have % out by :

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

    thank you

    ReplyDelete
    Replies
    1. Hi Adrar here I am trying to print % in the output

      Delete
  3. thank you for your hepl on those examples. on 23 to take out the "%" need to :
    lr_save_datetime("Today is %d/%m/%Y", DATE_NOW, "TodayDate");
    lr_output_message(lr_eval_string("{TodayDate}"));

    ReplyDelete
  4. How to add days every time using lr_save_datetime function

    ReplyDelete
  5. I want to add 10 days every time for this date- 3/10/2015(m/d/y).

    ReplyDelete

Post a Comment

Popular posts from this blog

NeoLoad Interview Questions and Answers

Here are some of the interview questions and answers on NeoLoad:
What is NeoLoad?
NeoLoad is a performance testing tool designed to test different types of web, standalone and mobile applications.
What is the difference between Loadrunner, JMeter and NeoLoad?
Click here for differences
What are the different counters you monitor in NeoLoad?
Average Response Time(requests), average response time(pages), average requests/s, average throughput, current response time(requests), current response time(pages), current requests, current throughput, current users count, controller cpu load, controller memory load etc.
What are the different type of tools you can integrate with NeoLoad?
App Dynamics, CA APM Integration, Dyna trace integration, HP ALM or Quality Center Integration, Java and Jamo Solutions M-eux Test Integration, Jenkins Integration, perfecto mobile integration, selenium integration.
What are the different type of Operating systems you can monitor?
Linux Monitor, Solaris Monitor, AIX …

Sitescope Monitoring Tool Features and Monitors

Why Sitescope is called Agentless Monitoring Tool?
HP SiteScope monitors the application/infrastructure/server/operating system without installing any agent software on the system to be monitored. This feature makes the installation, usage and maintenance of Sitescope simpler when compared with the any performance monitoring tools like Diagnostics.
Sitescope Monitors:
Sitescope has also upgraded and changed drastically to meet the rapidly changing technologies and environments like virtualization and cloud computing. Using Sitescope we can monitor different web servers, application servers and database servers. We can also monitor operating systems Windows, Linux, Sun Solaris, IBM AIX. It has more than 100 monitors including Weblogic, Websphere, SAP, SIEBEL, SNMP, LDAP, Network Monitor etc. HP SiteScope can also monitor cpu utilization, response time, disk space, and resource availability of a variety of host types and application platforms.
Sitescope Features:
SiteScope provides failover …

LR Functions with Examples | Loadrunner Functions with Examples

LR Functions in Loadrunner with Examples.

lr_abort Stops the script execution.lr_advance_param It will take the next value in the parameter list.lr_continue_on_error Continue on error even if the request is failed.lr_convert_string_encoding Converts a string to a UTF 8 or Unicode.lr_db_dataset_action Validates database contents by setting checkpoints.lr_db_connect Connects to a database.lr_db_dataset_action Performs an action on a dataset.lr_db_disconnect Disconnects from a database.lr_db_executeSQLStatement Submits an SQL statement to a database.lr_checkpoint Validates the value of a parameter against an expected value (checkpoint).lr_db_getValue Retrieves a value from a dataset.lr_debug_message Sends a debug message to the LoadRunner output or Application Management agent log file.lr_decrypt Decrypts an encoded string.lr_disable_ip_spoofing Disables IP Spoofing.lr_enable_ip_spoofing Enables IP Spoofing.lr_end_sub_transaction Marks the end of a sub-transaction.lr_end_transaction Mark…