Hi,
I'm using jQuery datepicker with Fullcalendar in an attempt to track employee attendance.
Everithing looks well till now with implementing jQuery datepicker and displaying the days-off for the employees in fullcalendar, but it is required to calculate and sum the employees off days, in order to see how many days-off had a person, how many days-of are remaining, etc.
Here I need your advice.... some guidance.
This is the script for datepicker:
I was thinking of calculating the difference between the 2 dates and than save it into another field.
But this is not working. Just like this. I feel I'm missing something here.
I'm using jQuery datepicker with Fullcalendar in an attempt to track employee attendance.
Everithing looks well till now with implementing jQuery datepicker and displaying the days-off for the employees in fullcalendar, but it is required to calculate and sum the employees off days, in order to see how many days-off had a person, how many days-of are remaining, etc.
Here I need your advice.... some guidance.
This is the script for datepicker:
- Code: Select all
<script type="text/javascript">
$(document).ready(function () {
$('#f_start_date').datepicker({
dateFormat: 'yy-mm-dd', // Set the desired date format
onSelect: function (dateText, inst) {
// Append the desired time to the selected date
var selectedDateTime = dateText + ' 08:00:00';
// Set the value of the input field
$(this).val(selectedDateTime);
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$('#f_end_date').datepicker({
dateFormat: 'yy-mm-dd', // Displayed date format
onSelect: function (dateText, inst) {
// Append the desired time to the selected date
var selectedDateTime = dateText + ' 15:00:00';
// Set the formatted date with time as the value of the input field
$(this).val(selectedDateTime);
}
});
});
</script>
I was thinking of calculating the difference between the 2 dates and than save it into another field.
- Code: Select all
<script type="text/javascript">
$(document).ready(function () {
$('#f_start_date').datepicker({
dateFormat: 'yy-mm-dd', // Set the desired date format
onSelect: function (dateText, inst) {
calculateAndSaveDifference();
}
});
$('#f_end_date').datepicker({
dateFormat: 'yy-mm-dd', // Displayed date format
onSelect: function (dateText, inst) {
calculateAndSaveDifference();
}
});
function calculateAndSaveDifference() {
var startDate = $('#f_start_date').datepicker('getDate');
var endDate = $('#f_end_date').datepicker('getDate');
// Ensure both dates are selected
if (startDate && endDate) {
var millisecondsPerDay = 24 * 60 * 60 * 1000; // Number of milliseconds in a day
var daysDifference = Math.round((endDate - startDate) / millisecondsPerDay);
// Calculate weekdays (skipping weekends)
var weekends = 0;
for (var i = 0; i <= daysDifference; i++) {
var currentDate = new Date(startDate.getTime() + i * millisecondsPerDay);
if (currentDate.getDay() === 0 || currentDate.getDay() === 6) {
weekends++;
}
}
var weekdaysDifference = daysDifference - weekends;
// Set the result in the f_daysoff field
$('#f_daysoff').val(weekdaysDifference);
}
}
});
</script>
But this is not working. Just like this. I feel I'm missing something here.