2017-01-12 10 views
1

Я пытаюсь рассчитать заработную плату на прошлой неделе сотрудников. Это означает, что текущая неделя не должна меня включать в расчет. Сейчас у меня есть -7 с текущей даты, чтобы проверить мои данные. Это мой кодкак рассчитать заработную плату на прошлой неделе в javascript?

var currentDate = new Date(); 
log.info(currentDate) 
var requiredDate=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-7) 
var start=Date.parse(requiredDate) 
var end=Date.parse(currentDate); 
query="taskCreateTimestamp:["+start+" TO "+end+"]"; 

Моя цель - рассчитать зарплату на прошлой неделе с понедельника по пятницу. Я взял -7, чтобы проверить только мои данные. Пожалуйста, помогите мне

+0

Ваш вопрос: «Как проверить временную метку в понедельник, вторник или какой-либо другой день в javascript?» и в коде, который вы просите рассчитать зарплату на прошлой неделе, вы хотите получить в результате – mean

+0

Извините за двусмысленность. Мне нужно рассчитать только зарплату на прошлой неделе. @mean –

+0

Итак, вы хотите, чтобы текущая дата и с предыдущего дня с этого момента я прав? – mean

ответ

0

проверить эту ссылку вы можете получить дату начала и окончания даты на прошлой неделе. и добавьте отметку времени '00: 00: 00 'к дате начала и '23: 59: 59' до даты окончания, если ваши данные имеют отметку времени.

get last week in javascript

0

«(зарплата/(рабочие дни месяца)) * (рабочие дни прошлой недели)» Выше линии должна быть ваша формула для расчета прошлой недели зарплаты. Таким образом, вам нужен метод, который вычисляет рабочие дни заданного интервала дат.

function getWorkingDays(startDate, endDate){ 
    var totalWorkingDays= 0; 
    var currentDate = startDate; 
    while (currentDate <= endDate) { 
     var weekDay = currentDate.getDay(); 
     if(weekDay != 0 && weekDay != 6) { 
      totalWorkingDays++; 
     } 
     currentDate.setDate(currentDate.getDate()+1); 
    } 
    return totalWorkingDays; 
} 

Затем укажите даты и примените формулу.

+0

Моя цель - рассчитать только заработную плату на прошлой неделе. Если сегодня понедельник, то это не означает текущий день. а также рассчитывать заработную плату в понедельник до пятницы. –

0

Я использовал ниже код в Jaggeryjs и отлично работал для меня. Я еще не тестировал, но получал ожидаемый результат.

var currentDate = new Date(); 
    var requiredDate; 
    log.info(currentDate) 
    var set=currentDate.setHours(0) 
    if(currentDate.getDay() == 1) 
    { 
    requiredDate=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-7) 
    } 
    else if(currentDate.getDay() == 2) 
    { 
    requiredDate=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-8) 
    } 
    else if(currentDate.getDay() == 3) 
    { 
    requiredDate=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-9) 
    } 
    else if(currentDate.getDay() == 4) 
    { 
    requiredDate=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-10) 
    } 
    else if(currentDate.getDay() == 5) 
    { 
    requiredDate=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-4) 
    } 
    else if(currentDate.getDay() == 6) 
    { 
    requiredDate=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-5) 
    } 
    else if(currentDate.getDay() == 7) 
    { 
    requiredDate=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-6) 
    } 
    var start=Date.parse(requiredDate) 
    log.info("Start-Date["+start+"]")   
    log.info("End----------------------------------------------") 
    var currentDate = new Date(); 
    log.info(currentDate)  
    var end; 
    if(currentDate.getDay() == 7) 
    { 
    end=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-2) 
    } 
    else if(currentDate.getDay() == 6) 
    { 
    end=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-1) 
    } 

    else if(currentDate.getDay() == 5) 
    { 
    end=Date.parse(currentDate) 
    log.info("End Date ["+end+"]") 
    } 
    else if(currentDate.getDay() == 4) 
    { 
    end=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-6) 
    } 
    else if(currentDate.getDay() == 3) 
    { 
    end=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-5) 
    } 
    else if(currentDate.getDay() == 2) 
    { 
    end=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-4) 
    } 
    else if(currentDate.getDay() == 1) 
    { 
    end=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-3) 
    } 


    end=Date.parse(currentDate); 
    log.info("End-Date["+end+"]")   
    query="taskCreateTimestamp:["+start+" TO "+end+"]"; 

 Смежные вопросы

  • Нет связанных вопросов^_^