Decrease bootstrap datepicker end date - javascript

I am using bootstrap datepicker for one on my project and set endDate like this
$('#daterange').data('daterangepicker').setEndDate('2017/03/12');
EndDate is somthign that i get from database, only problem is that on datepicker i have to set endDate but decrease one date, it measn if i have something from server like this
2017/03/12
I need to bind datepicker like this
$('#daterange').data('daterangepicker').setEndDate('2017/03/11');
is it possible to do that in frontend or i must go to server to correct, any simple solution?

you can use momentjs
moment("your date", "YYYY/MM/DD").subtract(1, 'days').format('YYYY/MM/DD');

What i will do:
1. get date from database ( 2017/03712)
2. change it to datetime format
3. decrease one day
4. setEndDate with correct format

Related

Get date inside jquery datepicker with not-ISO date format

I'm using jQuery datepicker to set the limit in a time series made with Highcharts for a personal project.
My date format is dd/mm/yyyy.
Following code works for sure till some weeks ago
onSelect: function () {
var minTime = $('input.highcharts-range-selector:eq(0)').datepicker("getDate").getTime();
var maxTime = $('input.highcharts-range-selector:eq(1)').datepicker("getDate").getTime();
}
But now I get following error:
"The specified value "03/02/2021" does not conform to the required format, "yyyy-MM-dd".
Searching I've understood that it depends on the fact that I'm using a format different from the ISO.
How I can fix this issue maintaining my date format?
Bonus question:
What could be changed from the last time that I've checked my site?
Thank you all

Bootstrap Datepicker:Disable date range from database

Does exist any possibility to disable date ranges from database? For example, I have date range
from 15.01.2021 to 21.01.2021 and from 24.01.2021 to 03.02.2021 and I want to disable these dates in datepicker and you couldn't be able to select from let's say from 17.01.2021 to 25.01.2021 but you can select from 22.01.2021 to 23.01.2021.
Database
On your database you could create a table of the like of invalid_interval(id, from, to). Store the invalid intervals and load it at your server-side, so you can serve the client-side by sending out this information.
Client-side
When you initialize your date picker, you can set your disabled dates like this:
var disabledDate = ['2020-1-1', '2020-1-15','2020-1-3'];
$('#datetimepicker1').datetimepicker({
disabledDates: disabledDate
});
Read more here. So, the attribute you were looking for is disabledDates and you can pass an array to it.

How can i add days to current date in laravel using js and jquery

I want to add number of days like 2,3,4 to current date of another data in laravel
If you mean add add number of days to current today date you can use
carbon
$num=4;
\Carbon\Carbon::now()->addDays($num);

React date picker with Material-UI

I'm using Date picker from Material UI. The code responsible for it looks like:
import { DatePicker } from 'redux-form-material-ui';
<Field
name="birthDate"
component={DatePicker}
placeholder="Birth Date"
container="inline"
format={ null }
/>
It's a lil' bit changed, by erikras for redux form, but works quite similar like normal material ui date picker.
http://www.material-ui.com/#/components/date-picker
My goal is
I'm sending it's value as API request, but unfortunately API accepts the Date only in YYYY-MM-DD format. And MaterialUI date picker gives
2017-05-04T22:00:00.000Z format. How can I change it into just 2017-05-04?
Thank you so much!
I havent tried the library itself in depth however if it return that date in that format you could just take what you need from that if it is a string you could use the substring() method and giving it the desired part start and end. lets Say
result = 2017-05-04T22:00:00.000Z;
var stringNeeded = result.substring(0,10)
instead of substring, I my opinion, better to use moment lib http://momentjs.com/
which allows to format date time values to any format you can imagine
moment(result).format('YYYY-MM-DD')

jQuery UI - Convert jQuery UI Datepicker to UNIX time

I'm using jQuery UI datepicker with time plugin. This is how I display time on the page in datepicker itself:
21.06.2012 08:00
I'd like to convert this time to UNIX timestamp before sending to backend. How can I do this?
I don't need to dispay UNIX time on the page, I only need to convert before posting. I've tried:
var d = Date.parse(value_of_datepicker);
but had no luck. It seems date should be formated in another way. Also I've tried several build-in datepicker functions, but all of them set date display view. Thanks.
If you use jQuery timepicker by Trent Richardson, you can do this: $("#your_datepicker").datetimepicker("getDate").getTime() / 1000
http://jsfiddle.net/d6Tky/
Remember that this function may return null if no date has been selected.

Categories