How to add Days in a islamic or HijriDate? - javascript

I have two text boxes.One is for taking StartDate from a islamic calender,so i am using jQuery Calendars Datepicker.
The ExpireDate textbox will automatically 60days from StartDate.so i am writing the logic in Onclose event of datepicker.
$(document).ready(function () {
ShowCalender();
});
function ShowCalender() {
var calendar = $.calendars.instance('islamic');
$('[id$=TxtOrderDate]').calendarsPicker({
calendar: calendar,
onClose: function (dates) {
var expiryDate = new Date(dates);
var x = 60;
expiryDate.setDate(expiryDate.getDate() + x);
document.getElementById('<%=TxtExpirationDate.ClientID%>').value = expiryDate;
},
showTrigger: '<img src="../../../_layouts/15/1033/Saudia/Images/calender.png" alt="Popup" class="trigger img">'
});
}
but here the ExpireDate fill with Date Sun Apr 24 03:00:00 UTC+0300 1436,which is a gregorian date.
expiredate mustbe the islamic Date.
How to add specific number of Days in FromDate?
Please help.

I think you should perform date operations (add date) in Gregorian format and then format back to Islamic date.
keith-wood.name/calendars

Related

Kendo Js: Show previous dates which are disabled

I am facing an issue using Kendo Js Date Time Picker.
The situation is: "I have a date time picker which can only allow dates from current time onwards. Those pages have already been saved, when I am trying to show the date, the dates aren't showing though it became a back date.
My concern is: The input should show the date which has already been saved(Whether that is past or present), but it shouldn't allow user to select back date.
The code are below.
<input id="datetimepicker" />
let options = { //Setting options for the datepicker
value: new Date(),
dateInput: true,
disableDates: function (date) {
if (date <= new Date()) {
return true;
} else {
return false;
}
},
};
$("#datetimepicker").kendoDateTimePicker(options);
const priorValue = new Date("8/31/2022 2:18 PM"); // Let Already selected date
let selector = "#datetimepicker";
let datetimepicker = $(selector).data("kendoDateTimePicker");
datetimepicker.value(priorValue);
datetimepicker.trigger("change");
function roundToNearest30(date) { //Function to round minutes to nearest 30 minute.
date = new Date(date);
const minutes = 30;
const ms = 1000 * 60 * minutes;
return new Date(Math.round(date.getTime() / ms) * ms);
}
For your reference a sample dojo
I need to show the selected date which is disabled.
You can use the disableDates configuration to disable prior dates and the month.content configuration to define how the dates will be rendered and show/hide dates conditionally:
<script id="cell-template" type="text/x-kendo-template">
<span class="#= (data.date <= new Date() && !isInArray(data.date, data.dates)) ? 'hidden' : 'visible' #">#= data.value #</span>
</script>
Here is a sample dojo.

How to set selected date on Jquery Calendar Plugin

So I am using the calendar app on a page that has a set date. I have it so when you click on the calendar, whatever is in the input that has the date, gets changed to the date you clicked on.
When you load into the page I want whatever date that is in the input to be what the calendar is set to. Thanks.
LINK TO PLUGIN - https://www.jqueryscript.net/time-clock/Simple-jQuery-Calendar-Date-Picker-Plugin-DCalendar.html
var pageDate = "4/04/2018";
<input class="date">
$('.date').val(pageDate);
// Make above date the selected date
// Code below is for setting input to date you select. Currently works.
$('.box').dcalendarpicker({
format: 'mm-dd-yyyy'
}).on('datechanged', function(e) {
console.log('Date change');
var d = e.date;
selectedDate = moment(d, 'MM-DD-YYYY');
var theDate = selectedDate._i;
$('.date').val(theDate);
var weekdayLongform = selectedDate.format("dddd, MMMM");
var dateLongform = selectedDate.format(" D");
var yearLongform = selectedDate.format(" YYYY");
});
Just set the date as the value of the input (in the same format specified in the plugin initialization). That will do the trick.
<!-- value specifid as mm-dd-yyyy -->
<input class="date" value="03-11-2018">

Date Picker Input

How can I validate my HTML date input so only certain dates of the week can be selected? I've seen this before on some booking websites. A date-picker calendar appears and days that the event is unavailable are grey out and cannot be selected.
I'm not sure where to start and I want to do this as my current project requires date input validation. The event is only available 3 days a week so it wouldn't make sense for the client to select a date when there is no event on.
Example, days are Monday, Wednesday and Friday so picking the Thursday 30th Nov shouldn't be an option.
With the first-line question in mind, what would be the simplest programming language to create a date-picker on to go with a data driven website?
If you are using jquery date picker:
<script>
var disableDates = ["22-11-2017", "23-11-2017"];
function disable(date) {
// convert it to my formate
dateToCheck = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
if ($.inArray(dateToCheck , disableDates) == -1) {
return [true, ""];
} else {
return [false, "", "disabled"];
}
}
$(function() {
$("#eventDate").datepicker({
dateFormat: 'dd-MM-yy',
beforeShowDay: disable
});
});
</script>

Set default time in bootstrap-datetimepicker

I want to set default time in this datetimepicker as 00:01 for the current date. Anyone tried that before? Having a tough time with it. It Seems simple.
$('#startdatetime-from').datetimepicker({
language: 'en',
format: 'yyyy-MM-dd hh:mm'
});
I need to use setDate, but I'm not sure how. I checked their code, but did not find a parameter for that.
None of the above worked for me, however I had success setting the default at time of instantiation.
JQuery
<script type="text/javascript">
$(function () {
var dateNow = new Date();
$('#datetimepicker').datetimepicker({
defaultDate:dateNow
});
});
</script>
Set a default input value as per this GitHub issue.
HTML
<input type="text" id="datetimepicker-input"></input>
jQuery
var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();
var output = d.getFullYear() + '/' +
(month<10 ? '0' : '') + month + '/' +
(day<10 ? '0' : '') + day;
$("#datetimepicker-input").val(output + " 00:01:00");
jsFiddle
JavaScript date source
EDIT - setLocalDate/setDate
var d = new Date();
var month = d.getMonth();
var day = d.getDate();
var year = d.getFullYear();
$('#startdatetime-from').datetimepicker({
language: 'en',
format: 'yyyy-MM-dd hh:mm'
});
$("#startdatetime-from").data('DateTimePicker').setLocalDate(new Date(year, month, day, 00, 01));
jsFiddle
For use datetime from input value, just set option useCurrent to false, and set in value the date
$('#datetimepicker1').datetimepicker({
useCurrent: false,
format: 'DD.MM.YYYY H:mm'
});
i tried to set default time for a picker and it worked:
$('#date2').datetimepicker({
format: 'DD-MM-YYYY 12:00:00'
});
this will save in database as : 2015-03-01 12:00:00
used for smalldatetime type in sql server
It works for me:
<script type="text/javascript">
$(function () {
var dateNow = new Date();
$('#calendario').datetimepicker({
locale: 'es',
format: 'DD/MM/YYYY',
defaultDate:moment(dateNow).hours(0).minutes(0).seconds(0).milliseconds(0)
});
});
</script>
use this after initialisation
$('.form_datetime').datetimepicker('update', new Date());
Hello developers,
Please try this code
var default_date= new Date(); // or your date
$('#datetimepicker').datetimepicker({
format: 'DD/MM/YYYY HH:mm', // format you want to show on datetimepicker
useCurrent:false, // default this is set to true
defaultDate: default_date
});
if you want to set default date then please set useCurrent to false otherwise setDate or defaultDate like methods will not work.
This Works for me. I have to use specially date format like this 'YY-MM-dd hh:mm' or 'YYYY-MM-dd hh:mm'
$('#datetimepicker1').datetimepicker({
format: 'YYYY-MM-dd hh:mm',
defaultDate: new Date()
});
This is my solution for your problem :
$('#startdatetime-from').datetimepicker({
language: 'en',
format: 'yyyy-MM-dd hh:mm'
}).on('dp.change', function (e) {
var specifiedDate = new Date(e.date);
if (specifiedDate.getMinutes() == 0)
{
specifiedDate.setMinutes(1);
$(this).data('DateTimePicker').date(specifiedDate);
}
});
This also work for setting a default hour or both.
Note that this code sample works with the useCurrent: false parameter too.
When the user pick a date, we check if the minute is 0 (hard-coded default value). In this case, we set a 1. Then, the user cannot select 0.
I solved my problem like this
$('#startdatetime-from').datetimepicker({
language: 'en',
format: 'yyyy-MM-dd hh:mm',
defaultDate:new Date()
});
Momentjs.com has good documentation on how to manipulate the date/time in relation to the current moment. Since Momentjs is required for the Datetimepicker, might as well use it.
var startDefault = moment().startof('day').add(1, 'minutes');
$('#startdatetime-from').datetimepicker({
defaultDate: startDefault,
language: 'en',
format: 'yyyy-MM-dd hh:mm'
});
By using Moment.js, i able to set the default time
var defaultStartTime = moment(new Date());
var _startTimeStr = "02:00 PM"
if (moment(_startTimeStr, 'HH:mm a').isValid()) {
var hr = moment(_startTimeStr, 'HH:mm a').hour();
var min = moment(_startTimeStr, 'HH:mm a').minutes();
defaultStartTime = defaultStartTime.hours(hr).minutes(min);
}
$('#StartTime').datetimepicker({
pickDate: false,
defaultDate: defaultStartTime
});
This works for me after a long hours of search , This solution is for Bootstrap datetimepicker version 4. when you have to set the default date in input field.
HTML
"input type='text' class="form-control" id='datetimepicker5' placeholder="Select to date" value='<?php echo $myDate?>'// $myDate is having value '2016-02-23' "
Note- If You are coding in php then you can set the value of the input datefield using php, but datetimepicker sets it back to current date when you apply datetimepicker() function to it. So in order to prevent it, use the given JS code
JAVASCRIPT
<script>
$('#datetimepicker5').datetimepicker({
useCurrent: false //this is important as the functions sets the default date value to the current value
,format: 'YYYY-MM-DD'
});
</script>

Change date format on datepicker

Hi i using this code to show a expiration date based on the select.
<script>
$(function(){
$("#date_picker").datepicker();
$("#Plano_Id").change(function() {
var offset = +$(this).find("option:selected").attr("title"), /* get days to add on date*/
theDate = new Date();
theDate.setDate(theDate.getDate() + offset);
$("#date_picker").datepicker("setDate", theDate);
});
});
</script>
But this returns the date in this format mm/dd/yyyy. I'm trying to show dd/mm/yyyy
For setting the format for a specific date control
$('#datepicker').datepicker({ dateFormat: 'dd/mm/yyyy' });
For setting it throughout your site/page, use
$.datepicker.setDefaults({ dateFormat: 'dd/mm/yyyy' });
//Note:Call this before initializing any date pickers
Use the dateFormat option: http://jqueryui.com/demos/datepicker/#date-formats

Categories

Resources