diff --git a/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb b/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb
index fd917f539b25122ea6260c43da1d43287cd0b74c..6adfdb8394d573cc602c1803ac87acb80a64a286 100644
--- a/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb
+++ b/notebooks/AGIPD/Chracterize_AGIPD_Gain_PC_NBC.ipynb
@@ -43,7 +43,7 @@
     "n_sequences = 3 # number of sequence files, starting for 0 to evaluate\n",
     "cluster_profile = \"noDB\" # The ipcluster profile to use\n",
     "local_output = True # output constants locally\n",
-    "db_output = True # output constants to database\n",
+    "db_output = False # output constants to database\n",
     "bias_voltage = 300 # detector bias voltage\n",
     "cal_db_interface = \"tcp://max-exfl016:8019\"  # the database interface to use\n",
     "mem_cells = 0.  # number of memory cells used, use 0 to auto-derive\n",
@@ -53,8 +53,10 @@
     "instrument = \"MID\"\n",
     "high_res_badpix_3d = False # set this to True if you need high-resolution 3d bad pixel plots. Runtime: ~ 1h\n",
     "acq_rate = 0. # the detector acquisition rate, use 0 to try to auto-determine\n",
-    "dont_use_dir_date = False\n",
-    "gain_setting = 0.1 # gain setting can have value 0 or 1, Default=0.1 for no (None) gain-setting"
+    "use_dir_creation_date = True\n",
+    "creation_time = \"\" # To overwrite the measured creation_time. Required Format: YYYY-MM-DD HR:MN:SC.ms e.g. 2019-07-04 11:02:41.00\n",
+    "gain_setting = 0.1 # gain setting can have value 0 or 1, Default=0.1 for no (None) gain-setting\n",
+    "karabo_da_control = \"AGIPD1MCTRL00\" # karabo DA for control infromation"
    ]
   },
   {
@@ -94,7 +96,7 @@
     "from cal_tools.influx import InfluxLogger\n",
     "from cal_tools.enums import BadPixels\n",
     "from cal_tools.plotting import show_overview, plot_badpix_3d\n",
-    "from cal_tools.agipdlib import get_acq_rate, get_num_cells\n",
+    "from cal_tools.agipdlib import get_acq_rate, get_num_cells, get_gain_setting\n",
     "from datetime import datetime\n",
     "\n",
     "IL_MODE = interlaced \n",
@@ -122,13 +124,31 @@
     "else:\n",
     "    loc = \"MID_DET_AGIPD1M-1\"\n",
     "    dinstance = \"AGIPD1M2\"\n",
-    "print(\"Detector in use is {}\".format(loc))\n",
+    "print(\"Detector in use is {}\".format(loc))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "control_fname = f'{in_folder}/r{runs[0]:04d}/RAW-R{runs[0]:04d}-{karabo_da_control}-S00000.h5'\n",
     "\n",
-    "# Convert gain-setting in case of still being 0.1\n",
     "if gain_setting == 0.1:\n",
-    "    gain_setting = None\n",
-    "    \n",
-    "print(\"Gain setting: {}\".format(gain_setting))"
+    "    if creation_time.replace(tzinfo=None) < dateutil.parser.parse('2020-01-31'):\n",
+    "        print(\"Set gain-setting to None for runs taken before 2020-01-31\")\n",
+    "        gain_setting = None\n",
+    "    else:\n",
+    "        try:\n",
+    "            gain_setting = get_gain_setting(control_fname, h5path_ctrl)\n",
+    "        except Exception as e:\n",
+    "            print(f'Error while reading gain setting from: \\n{control_fname}')\n",
+    "            print(e)\n",
+    "            print(\"Gain setting is not found in the control information\")\n",
+    "            print(\"Data will not be processed\")\n",
+    "            sequences = []\n",
+    "print(f\"Gain setting: {gain_setting}\")"
    ]
   },
   {
@@ -154,7 +174,7 @@
     "run = runs[0]\n",
     "bursts_per_file = []\n",
     "channel = 0\n",
-    "creation_time=None\n",
+    "\n",
     "for seq in range(seqs):\n",
     "    fname = os.path.join(path_temp.format(run),\n",
     "                         image_name_temp.format(run, channel, seq))\n",
@@ -164,7 +184,19 @@
     "        acq_rate = get_acq_rate(fname, loc, channel)\n",
     "        print(\"Acquisition rate set from file: {} MHz\".format(acq_rate))\n",
     "    \n",
-    "    if not dont_use_dir_date:\n",
+    "    # Run's creation time:\n",
+    "    if creation_time:\n",
+    "        try:\n",
+    "            creation_time = datetime.datetime.strptime(creation_time, '%Y-%m-%d %H:%M:%S.%f')\n",
+    "        except Exception as e:\n",
+    "            print(f\"creation_time value error: {e}.\" \n",
+    "                   \"Use same format as YYYY-MM-DD HR:MN:SC.ms e.g. 2019-07-04 11:02:41.00/n\")\n",
+    "            creation_time = None\n",
+    "            print(\"Given creation time wont be used.\")\n",
+    "    else:\n",
+    "        creation_time = None\n",
+    "\n",
+    "    if not creation_time and use_dir_creation_date:\n",
     "        creation_time = get_dir_creation_date(in_folder, run)\n",
     "    \n",
     "    if mem_cells == 0:\n",
@@ -531,7 +563,7 @@
     "                                                     Conditions.Dark.AGIPD(\n",
     "                                                         memory_cells=mem_cells,\n",
     "                                                         bias_voltage=bias_voltage, acquisition_rate=acq_rate,\n",
-    "                                                     gain_setting=gain_setting),\n",
+    "                                                         gain_setting=gain_setting),\n",
     "                                                         np.zeros((128, 512, mem_cells, 3)),\n",
     "                                                     cal_db_interface, creation_time=creation_time)\n",
     "    print(\"Offset for {} was injected on {}\".format(qm, when))\n",
@@ -542,7 +574,7 @@
     "                                                     Conditions.Dark.AGIPD(\n",
     "                                                         memory_cells=mem_cells,\n",
     "                                                         bias_voltage=bias_voltage, acquisition_rate=acq_rate,\n",
-    "                                                     gain_setting=gain_setting),\n",
+    "                                                         gain_setting=gain_setting),\n",
     "                                                         np.zeros((128, 512, mem_cells, 3)),\n",
     "                                                     cal_db_interface, creation_time=creation_time)\n",
     "    print(\"Noise for {} was injected on {}\".format(qm, when))\n",
@@ -553,7 +585,7 @@
     "                                                     Conditions.Dark.AGIPD(\n",
     "                                                         memory_cells=mem_cells,\n",
     "                                                         bias_voltage=bias_voltage, acquisition_rate=acq_rate,\n",
-    "                                                     gain_setting=gain_setting),\n",
+    "                                                         gain_setting=gain_setting),\n",
     "                                                         np.zeros((128, 512, mem_cells, 3)),\n",
     "                                                     cal_db_interface, creation_time=creation_time)\n",
     "    print(\"Threshold for {} was injected on {}\".format(qm, when))\n",
@@ -1387,7 +1419,13 @@
     "        metadata.detector_condition = condition\n",
     "\n",
     "        # specify the a version for this constant\n",
-    "        metadata.calibration_constant_version = Versions.Now(device=getattr(getattr(Detectors, dinstance), qm))\n",
+    "        \n",
+    "        if creation_time is None:\n",
+    "            metadata.calibration_constant_version = Versions.Now(device=getattr(Detectors.AGIPD1M1, qm))\n",
+    "        else:\n",
+    "            metadata.calibration_constant_version = Versions.Timespan(device=getattr(Detectors.AGIPD1M1, qm),\n",
+    "                                                                      start=creation_time)\n",
+    "        \n",
     "        metadata.calibration_constant_version.raw_data_location = file_loc\n",
     "        metadata.send(cal_db_interface)\n",
     "        \n",
@@ -1404,7 +1442,11 @@
     "        metadata.detector_condition = condition\n",
     "\n",
     "        # specify the a version for this constant\n",
-    "        metadata.calibration_constant_version = Versions.Now(device=getattr(getattr(Detectors, dinstance), qm))\n",
+    "        if creation_time is None:\n",
+    "            metadata.calibration_constant_version = Versions.Now(device=getattr(Detectors.AGIPD1M1, qm))\n",
+    "        else:\n",
+    "            metadata.calibration_constant_version = Versions.Timespan(device=getattr(Detectors.AGIPD1M1, qm),\n",
+    "                                                                      start=creation_time)\n",
     "        metadata.calibration_constant_version.raw_data_location = file_loc\n",
     "        metadata.send(cal_db_interface)"
    ]