797 0 0 0
Last Updated : 2025-04-28 22:20:38
this snippet will teach you how to set current date and current datetime in input date and input datetime-local specially on fire bootstrap modal
On this snippet I will provide jquery snippet for filling input date or datetime-local with current date or current datetime specially on fire bootstrap modal like this
$(document).on('shown.bs.modal', "#adminModal", function (e) {
$('#add_item_reading').focus();
// ASSIGN CURRENT DATE TO INPUT TYPE DATE
var now = new Date();
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var today = (day)+"/"+(month)+"/"+ now.getFullYear();
$('#datePicker').val(today);
// ASSIGN CURRENT DATETIME TO INPUT TYPE DATETIME-LOCAL
let dateControl = document.querySelector('input[type="datetime-local"]');
dateControl.value = new Date().toJSON().slice(0,19);
}) ;