You need to create the datepicker in advance.
So if you have this HTML:
<div class="input-group">
<input type="text" class="form-control" id="datetext"/>
<span class="input-group-btn">
<button class="btn btn-default" type="button" id="datebtn">
<span class="glyphicon glyphicon-calendar"></span>
</button>
</span>
</div>
Then the following JavaScript will work, with the options passed into the datepicker when it is initialized:
$('#datetext').datepicker({ autoclose: true,
format: "dd MM yyyy"
})
.off('focus');
$('#datebtn').click(function () {
$('#datetext').datepicker('show');
});