Skip to main content

Calculate a few days, hours and minutes between two dates

In the process of building YIDA applications, you may encounter the following problems.

  • In the salary management system, it is usually necessary to calculate and summarize the employee's working hours according to the employee's attendance time to determine the salary, overtime pay or vacation time.
  • In the production management system, it is usually necessary to calculate the production cycle to decide how to arrange production and estimate the delivery or delivery time.
  • In the task management system, it is usually necessary to calculate the completion time of the task and calculate the human efficiency to decide how to arrange manpower in the future.

Prerequisites

This tutorial uses the form formula of YIDA. You can first understand the followingForm formula.

Effect

Implementation steps

Create a common form page

Create a common form page. For more information, seeCommon form.

Drag the following components into the canvas area.

  • Date: Named as the start date
  • Date: Named end date
  • Numerical value: Named as the number of milliseconds at intervals
  • Single line text: Named interval

Add Form formula

Select quick configuration for the start date. The default value is today.

End date select quick configuration and specify 7 days after the start date.

Select the formula to edit the number of milliseconds and configure the formula shown in the following figure. You can also directly copy the formula source code and pay attention to modifying the fields.

{"text":"IF(OR(ISEMPTY(​开始日期​),ISEMPTY(​结束日期​)),0,​结束日期​-​开始日期​)","marks":[{"from":{"line":0,"ch":14,"sticky":null},"to":{"line":0,"ch":20,"sticky":null},"value":"dateField_ladso6iv","invalid":false},{"from":{"line":0,"ch":30,"sticky":null},"to":{"line":0,"ch":36,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":41,"sticky":null},"to":{"line":0,"ch":47,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":48,"sticky":null},"to":{"line":0,"ch":54,"sticky":null},"value":"dateField_ladso6iv","invalid":false}],"isCmData":true}

Select the formula to edit the interval and configure the formula shown in the following figure. You can also copy the formula source code directly, and pay attention to modifying the fields.

{"text":"IF(OR(ISEMPTY(​开始日期​),ISEMPTY(​结束日期​)),\"0天0小时0分钟0秒\",CONCATENATE(TEXT(INT((​结束日期​-​开始日期​)/86400000),\"#天\"),TEXT(INT(((​结束日期​-​开始日期​)-INT((​结束日期​-​开始日期​)/86400000)*86400000)/3600000),\"#小时\"),TEXT(INT(((​结束日期​-​开始日期​)-INT((​结束日期​-​开始日期​)/3600000)*3600000)/60000),\"#分钟\"),TEXT(INT(((​结束日期​-​开始日期​)-INT((​结束日期​-​开始日期​)/60000)*60000)/1000),\"#秒\")))","marks":[{"from":{"line":0,"ch":14,"sticky":null},"to":{"line":0,"ch":20,"sticky":null},"value":"dateField_ladso6iv","invalid":false},{"from":{"line":0,"ch":30,"sticky":null},"to":{"line":0,"ch":36,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":74,"sticky":null},"to":{"line":0,"ch":80,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":81,"sticky":null},"to":{"line":0,"ch":87,"sticky":null},"value":"dateField_ladso6iv","invalid":false},{"from":{"line":0,"ch":116,"sticky":null},"to":{"line":0,"ch":122,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":123,"sticky":null},"to":{"line":0,"ch":129,"sticky":null},"value":"dateField_ladso6iv","invalid":false},{"from":{"line":0,"ch":136,"sticky":null},"to":{"line":0,"ch":142,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":143,"sticky":null},"to":{"line":0,"ch":149,"sticky":null},"value":"dateField_ladso6iv","invalid":false},{"from":{"line":0,"ch":198,"sticky":null},"to":{"line":0,"ch":204,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":205,"sticky":null},"to":{"line":0,"ch":211,"sticky":null},"value":"dateField_ladso6iv","invalid":false},{"from":{"line":0,"ch":218,"sticky":null},"to":{"line":0,"ch":224,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":225,"sticky":null},"to":{"line":0,"ch":231,"sticky":null},"value":"dateField_ladso6iv","invalid":false},{"from":{"line":0,"ch":276,"sticky":null},"to":{"line":0,"ch":282,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":283,"sticky":null},"to":{"line":0,"ch":289,"sticky":null},"value":"dateField_ladso6iv","invalid":false},{"from":{"line":0,"ch":296,"sticky":null},"to":{"line":0,"ch":302,"sticky":null},"value":"dateField_ladso6iw","invalid":false},{"from":{"line":0,"ch":303,"sticky":null},"to":{"line":0,"ch":309,"sticky":null},"value":"dateField_ladso6iv","invalid":false}],"isCmData":true}

Save page

Video tutorial

Try it online

This doc is generated using machine translation. Any discrepancies or differences created in the translation are not binding and have no legal effect for compliance or enforcement purposes.
Copyright © 2024钉钉(中国)信息技术有限公司和/或其关联公司浙ICP备18037475号-4