dfmmalaw
6/26/2017 - 4:30 PM

Creating Bootstrap datepicker and using Moment to convert time format from C# to JS readable

Creating Bootstrap datepicker and using Moment to convert time format from C# to JS readable

// moment code used to convert from C# millisecond syntax to readable format
// first one is not nullable because it is required
DateDosSigned(moment(row.DateDosSigned).format('MM/DD/YYYY'));
TestDetailsProvided(row.DateTestBegin == null ? "" : moment(row.DateTestBegin).format('MM/DD/YYYY'));
CompleteDate(row.ActiveDate == null ? "" : moment(row.ActiveDate).format('MM/DD/YYYY'));
InactiveDate(row.InactiveDate == null ? "" : moment(row.InactiveDate).format('MM/DD/YYYY'));

// activate the datepicker on page load
$(document).ready(function () {
    $('.datepicker').datepicker({
        autoclose: true,
        clearBtn: true
    });
});

<!--added the datepicker class to "input" element-->
<div class="form-group">
    <label class="label-col col-lg-6 col-md-6 col-sm-4 col-xs-12 control-label" for="dosSignedDate">Date DOS Signed<span class="warn">*</span></label>
    <div class="col-lg-6 col-md-6 col-sm-8 col-xs-12">
        <input class="form-control max350 datepicker" id="dosSignedDate" name="dosSignedDate" type="text" data-bind="textInput:DateDosSigned">
    </div>
</div>