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:


Example 1:


   return 0;

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");
Output: Today is (with abbreviated name) Fri

Example 3:

lr_save_datetime("Today is (with full name) %A",DATE_NOW,"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");
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");
Output: This month is (with full name) June

Example 6:

lr_save_datetime("%c Date with time stamp",DATE_NOW,"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");
Output: Only Todays Date 23

Example 8:

lr_save_datetime("Gives 24 Hours %H",DATE_NOW,"24_Hours");
Output: Gives 24 Hours 11

Example 9:

lr_save_datetime("Gives 12 Hours %I",DATE_NOW,"12_hours");
Output: Today is (with full name) Friday

Example 10:

lr_save_datetime("It gives number of day in a year %j",DATE_NOW,"TodayNumber");
Output: It gives number of day in a year 143

Example 11:

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

Example 12:

lr_save_datetime("Gives present minute %M",DATE_NOW,"Minute");
Output: Gives present minute 56

Example 13:

lr_save_datetime("Gives AM/PM %p",DATE_NOW,"AM_PM");
Output: Gives AM/PM AM

Example 14:

lr_save_datetime("Gives Seconds %S",DATE_NOW,"Seconds");
Output: Gives Seconds 18

Example 15:

lr_save_datetime("Gives week no of the year (with Sunday as 01) %U",DATE_NOW,"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");
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");
Output: Week No of the Year (with Monday as 01) 20

Example 18:

lr_save_datetime("It gives Todays Date %x",DATE_NOW,"TodaysDate");
Output: It gives Todays Date 5/23/2014

Example 19:

lr_save_datetime("It gives time now %X",DATE_NOW,"TimeNow");
Output: It gives time now 11:56:18 AM

Example 20:

lr_save_datetime("Year without centuary %y",DATE_NOW,"YearWOCentuary");
Output: Year without centuary 14

Example 21:

lr_save_datetime("Year with centuary %Y",DATE_NOW,"YearWCentuary");
Output: Year with centuary 2014

Example 22:

lr_save_datetime("Abbreviation of time zone %Z",DATE_NOW,"TimeZoneAbbr");
Output: Abbreviation of time zone India Standard Time

Example 23:

lr_save_datetime("Today is %d%%%Y"DATE_NOW"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)


  1. the out put will be formated as folowing

    lr_save_datetime("Today is %d/%m/%Y", DATE_NOW, "TodayDate");

    thanks for ur examples they are really helpful

  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");

    thank you

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

  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");

  4. How to add days every time using lr_save_datetime function

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


Post a Comment

Popular posts from this blog

File operations in loadrunner with examples

In this post I will explain how to capture a value from server response and save to a text file using vugen. How to capture and save to text file using loadrunner: First I have recorded the script using and then i searched for IBM. We will get 10 results. I have captured all the 10 values and saved to a file. Here is the code for that.

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 mon

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-tr