mercredi 27 mai 2020

Date editing : remove the zero prefix from the month

The following code returns me next Friday date. I have added an IF in order to remove the first 0 from the month variable,since I need it without the 0 prefix. But it doesn't work. What is the error I'm doing ?

<script type="text/javascript">

function nextWeekdayDate(date, day_in_week) {
var ret = new Date(date||new Date());
ret.setDate(ret.getDate() + (day_in_week - 1 - ret.getDay() + 7) % 7 + 1);
return ret;
}

var date = new Date();
console.log(nextWeekdayDate(date, 5));

  $(document).ready(function() {
  $('#button').click(function(e) {  
      var date = nextWeekdayDate(null, 5);
      var [yyyy, mm, dd] = date.toISOString().split('T')[0].split('-');

      if ([mm hasPrefix:@"0"] && [string length] > 1) {
  mm = [string substringFromIndex:1];
}

      window.open(`https://www.mydinamiclink.com/`+mm);

                      });

      });


</script>

thanks for your help

Aucun commentaire:

Enregistrer un commentaire