diff --git a/cdr.c b/cdr.c
index ce908d82fd78c80bc202970fd9b873520eafd916..58c5e02dbacdf42993b9b8bfd1e45b68096e19e3 100644
--- a/cdr.c
+++ b/cdr.c
@@ -657,6 +657,11 @@ void ast_cdr_end(struct ast_cdr *cdr)
 			ast_log(LOG_WARNING, "CDR on channel '%s' has not started\n", chan);
 		if (ast_tvzero(cdr->end))
 			cdr->end = ast_tvnow();
+		cdr->duration = cdr->end.tv_sec - cdr->start.tv_sec + (cdr->end.tv_usec - cdr->start.tv_usec) / 1000000;
+		if (!ast_tvzero(cdr->answer))
+			cdr->billsec = cdr->end.tv_sec - cdr->answer.tv_sec + (cdr->end.tv_usec - cdr->answer.tv_usec) / 1000000;
+		else
+			cdr->billsec = 0;
 		cdr = cdr->next;
 	}
 }
@@ -804,11 +809,6 @@ static void post_cdr(struct ast_cdr *cdr)
 			ast_log(LOG_WARNING, "CDR on channel '%s' lacks end\n", chan);
 		if (ast_tvzero(cdr->start))
 			ast_log(LOG_WARNING, "CDR on channel '%s' lacks start\n", chan);
-		cdr->duration = cdr->end.tv_sec - cdr->start.tv_sec + (cdr->end.tv_usec - cdr->start.tv_usec) / 1000000;
-		if (!ast_tvzero(cdr->answer))
-			cdr->billsec = cdr->end.tv_sec - cdr->answer.tv_sec + (cdr->end.tv_usec - cdr->answer.tv_usec) / 1000000;
-		else
-			cdr->billsec = 0;
 		ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
 		AST_LIST_LOCK(&be_list);
 		AST_LIST_TRAVERSE(&be_list, i, list) {
@@ -1121,6 +1121,7 @@ static int do_reload(void)
 	const char *batchsafeshutdown_value;
 	const char *size_value;
 	const char *time_value;
+	const char *end_before_h_value;
 	int cfg_size;
 	int cfg_time;
 	int was_enabled;
@@ -1171,6 +1172,8 @@ static int do_reload(void)
 			else
 				batchtime = cfg_time;
 		}
+		if ((end_before_h_value = ast_variable_retrieve(config, "general", "endbeforehexten")))
+			ast_set2_flag(&ast_options, ast_true(end_before_h_value), AST_OPT_END_CDR_BEFORE_H_EXTEN);
 	}
 
 	if (enabled && !batchmode) {
diff --git a/configs/cdr.conf.sample b/configs/cdr.conf.sample
index 2d45e0d566dd3bf23cd99761366ad6a72d30a0b1..e8b3a6886c1c59fa9882f1d2e3dd738d0685c822 100644
--- a/configs/cdr.conf.sample
+++ b/configs/cdr.conf.sample
@@ -49,6 +49,13 @@
 ; is "yes".
 ;safeshutdown=yes
 ;
+
+; Normally, CDR's are not closed out until after all extensions are finished
+; executing.  By enabling this option, the CDR will be ended before executing
+; the "h" extension so that CDR values such as "end" and "billsec" may be
+; retrieved inside of of this extension.
+;endbeforehexten=no
+
 ;[csv]
 ;usegmtime=yes ;log date/time in GMT
 ;loguniqueid=yes ;log uniqueid
diff --git a/include/asterisk/options.h b/include/asterisk/options.h
index 4c4031a5a21af4deaae750984029220bffc6d4c1..73d98b2755e7e14163ebe3b22f47908f1eea9e49 100644
--- a/include/asterisk/options.h
+++ b/include/asterisk/options.h
@@ -69,7 +69,9 @@ enum ast_option_flags {
 	/*! Transmit Silence during Record() */
 	AST_OPT_FLAG_TRANSMIT_SILENCE = (1 << 17),
 	/*! Suppress some warnings */
-	AST_OPT_FLAG_DONT_WARN = (1 << 18)
+	AST_OPT_FLAG_DONT_WARN = (1 << 18),
+	/*! End CDRs before the 'h' extension */
+	AST_OPT_END_CDR_BEFORE_H_EXTEN = (1 << 19)
 };
 
 #define ast_opt_exec_includes		ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES)
@@ -91,6 +93,7 @@ enum ast_option_flags {
 #define ast_opt_reconnect		ast_test_flag(&ast_options, AST_OPT_FLAG_RECONNECT)
 #define ast_opt_transmit_silence	ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE)
 #define ast_opt_dont_warn		ast_test_flag(&ast_options, AST_OPT_FLAG_DONT_WARN)
+#define ast_opt_end_cdr_before_h_exten	ast_test_flag(&ast_options, AST_OPT_END_CDR_BEFORE_H_EXTEN)
 
 extern struct ast_flags ast_options;
 
diff --git a/pbx.c b/pbx.c
index 458f9d707de719f904baaf011ad33a8cb8ab2e8b..eca359cc74cad1621f7bdd2b499e86780b7ebc76 100644
--- a/pbx.c
+++ b/pbx.c
@@ -2278,6 +2278,8 @@ static int __ast_pbx_run(struct ast_channel *c)
 		ast_log(LOG_WARNING, "Don't know what to do with '%s'\n", c->name);
 out:
 	if ((res != AST_PBX_KEEPALIVE) && ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num)) {
+		if (c->cdr && ast_opt_end_cdr_before_h_exten)
+			ast_cdr_end(c->cdr);
 		c->exten[0] = 'h';
 		c->exten[1] = '\0';
 		c->priority = 1;