JMeter – How to Write a BeanShell Code to Get Current Date or Feature Date or Older Date

Here I am going to explain and write a simple snippet that show how you can write a short code in JMeter BeanShell code that pull out the current date or you can modify to get feature date or previuos old date.

This is a simple code.

import java.text.SimpleDateFormat;
import java.util.Date;
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String formattedDate = df.format(date);

Above Code Explanation:

  • The first two lines is defined to get java definations.
  • Next line will get the current system date. <Date date = new Date();>
  • Next line will addition or substract the current date by adding + (plus) or – (minus) number of days future or previous. <date.setDate(date.getDate()+5);> This will add 5 days from the current date.
  • Next line format the current date as per your requirement. <(“dd/MM/yyyy”);> you can format as you like ddMMyyyy, dd-MM-yyyy, read more format dates here.
    • Even you can defind directly below fucntion in JMeter, but not in BeanSheet.
      • ("dd-mmm-yyyy HHmmss") this will get 20-032-2015 233224
      • ("d-MMM-yyyy hhmmss") this will get 20-May-2015 113224
      • ("dd-m-yyyy hhmmss") this will get 20-32-2015 113224
      • ("D-M-yyyy hhmmss") this will get 140-5-2015 113224
      • ("DD-MM-yyyy") this will get 140-05-2015
  • The Next line is format the date as we required.
  • The Final line is put the required date into a variable, that you can parameterized in your JMeter Script with ${date} variable.

I hope you got the required information from this artilce post, If you have any doubts, or questions, you can ask from below comment session, I will explan and give more detailed on this topic.

You May Interest to read How To Clear All Results in JMeter using BeanShell Code

JMeter – How To Clear All Results using BeanShell Code with Example

JMeter BeanShell Code to Clearn Results

Here you can learn how to write a BeanShell code that call during the JMeter test run and Clear required Listener Results. Please use below code, copy and paste into your JMeter BeanSheel code area and Save JMeter and Run it. You can see that when this code calls in JMeter during the test run, it will clean all test results.

import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.JMeterGUIComponent;
import org.apache.jmeter.gui.tree.JMeterTreeNode;
import org.apache.jmeter.samplers.Clearable;"Clearing All ...");
guiPackage = GuiPackage.getInstance();
for (JMeterTreeNode node : guiPackage.getTreeModel().getNodesOfType(Clearable.class)) {
    JMeterGUIComponent guiComp = guiPackage.getGui(node.getTestElement());
    if (guiComp instanceof Clearable){
        Clearable item = (Clearable) guiComp;
        try {
        } catch (Exception ex) {
            log.error("Can't clear: "+node+" "+guiComp, ex);

Thanks for reading this, if you are itnerested to more, then you may read BeanShell Code to Get Current Date

How To Make A New Directory With Read and Write (0777) Options Using With PHP Code

mkdir function in PHP
mkdir function in PHP
mkdir function in PHP

Hello Reader,

Today I am going to show you how to make a directory using PHP code snippet in cPanel folder in any location. Just follow my step by step method, from the below listed topic you will going to learn how easily you can create or make a new directory or folder.

Use blow PHP Code to create a Directory or a Folder.

	$oldmask = umask(0);
	mkdir("./ExistingFolderName/NewFolderName", 0777, true);

Please ask any questions about this or add your comments on this topic below.