0

I am using Babakhani Datepicker and actually i have done substract thing from datepicker but it does not work on this , so i want to cast -7 days from currentdate

I have done it on console Like this

var nowDate = new Date();
var days = 7;
nowDate.setDate(nowDate.getDate() - days);
var mamat = nowDate.toISOString().split('T')[0];
console.log(mamat);

but as i am using PERSIAN not GREGORIAN i cant convert it

I have to use it on this

$(".persianDate").pDatepicker();

today date is 1/13/2019 and i want it to be 1/7/2019

Babakhani Source :

http://babakhani.github.io/PersianWebToolkit/doc/datepicker/options/

1 Answers1

0
let date = new Date();
date.setDate(date.getDate()-1);
console.log(date.toLocaleDateString());
// Woud log:
// 1/12/2019
console.log(date.toLocaleDateString('fa-IR'));
// Woud log:
// ۱۳۹۷/۱۰/۲۲

If you want to set the calendar, then you can pass the desired calendar as an argument to the toLocaleDateString method, as per the MDN docs. For example, passing 'ar-EG' will result in Arabic digits.

Possible duplicate of Subtract days from a date in JavaScript.

rmolinamir
  • 1,121
  • 14
  • 15
  • It is ok but i dont know how to pass or define it to $(".persianDate").pDatepicker(); –  Jan 13 '19 at 07:44
  • I have no experience with that library, but if you pass 'fa-IR' as an argument to the toLocaleDateString method it'll convert it to Solar Hijri. I updated the answer to reflect this. Also, check the MDN doc I provided to you if you have any further doubts, this is among the information. – rmolinamir Jan 13 '19 at 08:55
  • No problem, glad it helped. – rmolinamir Jan 13 '19 at 19:53