Yesterday's date

PHaRTnONu

Client
Регистрация
01.10.2016
Сообщения
340
Благодарностей
48
Баллы
28
How do i get the prior days date?

tried a few java executions to no luck, idk just lost a little help would be nice
 

PHaRTnONu

Client
Регистрация
01.10.2016
Сообщения
340
Благодарностей
48
Баллы
28
sorry should have been more specific
i have used

JavaScript:
var YesterdaysDate = new Date(new Date().setDate(new Date().getDate()-1));
Result сказал(а):
Mon Nov 21 08:55:11 MST 2016
but i need it to output only MM/DD/YYYY
not as its coming...


also have
JavaScript:
function getYesterdaysDate() {
  var date = new Date();
  date.setDate(date.getDate()-1);
  return date.getDate() + '/' + (date.getMonth()+1) + '/' + date.getFullYear();
}function formatDate(d) {

  if (!d) return null;

  var date = d.getDate(), month = d.getMonth(), year = d.getFullYear();

  return addZero(date)+"/"+addZero(month+1)+"/"+year;

}
function addZero(val) {
  return val<10? "0"+val: val;
}

var d = new Date();
d.setDate(d.getDate() - 1);
formatDate(d);
gives
results сказал(а):

still not quite what i want
 
Последнее редактирование:

PHaRTnONu

Client
Регистрация
01.10.2016
Сообщения
340
Благодарностей
48
Баллы
28
SOLUTION Found:

JavaScript:
var d = new Date();
var yesterday = d.getMonth() + '/' + (d.getDate() -1) + '/' + d.getFullYear();
but that will mess up any day that is on the 1st 9dec 1st youre gonna have a 12/0/2016 result...

JavaScript:
var d = new Date();
var date = d.getMonth() + '/' + d.getDate() + '/' + d.getFullYear();

//SET to yesterday setDate rollover the month part if its start of a month.
d.setDate(d.getDate() - 1);
var yesterday = d.getMonth()+1 + '/' + d.getDate() + '/' + d.getFullYear();
results сказал(а):

(month needs the +1 other wise on the 1st you'll also go back a month on top!)
on December 1st you'll end up on 10/31/2016 if you don't have the +1 on the month....
 
Последнее редактирование:

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)