php - 使用间隔(以周数为单位)和开始日期计算未来日期
问题描述
我正在尝试编写一个函数来计算需要检查一件设备的下一个日期。我正在使用下面的代码(它不完整。)
function get_next_check(){
$today = date(get_option('date_format'));
$first_check = types_get_field_meta_value( 'first_check', $post_id );
// Interval is a number of weeks- ie. month = 4, year = 52
$interval = types_get_field_meta_value( 'interval', $post_id );
// Calculate the next date after today that the check needs to be performed
$next_check = ;
return $next_check;
}
add_shortcode( 'next_check', 'get_next_check' );
我猜我需要创建一个包含所有可能日期的数组,并将每个日期与今天的日期进行比较,只返回下一个日期?
解决方案
您可以根据 Greg Schmidt 的建议来实现这一点,或者通过执行以下操作:
// Calculate the next date after today that the check needs to be performed
$next_check = date(get_option('date_format'), strtotime($today." ".$interval." weeks"));
推荐阅读
- javascript - Onclick 显示 div 重叠/隐藏其他
- computer-vision - 计算机视觉中的 3D 重建中的术语在线和离线指的是什么?
- javascript - 从 Facebook 帖子上的 Chrome 扩展触发 React 组件的状态更改
- javascript - React 保存动态 UI 组件
- reactjs - Gatsby + React 预订日历:“WebpackError: ReferenceError: self is not defined” on 'gatsby build' 但 'gatsby develop' 工作正常
- java - 使用包含带有 RestTemplate 的数组的单个字段为 json 创建 POJO
- firebase - Firebase 安全规则:“规则集使用旧版本”,当前版本是什么?
- postgresql - PostgreSQL - 将字符串转换为 ASCII 整数
- git - 从 Develop 分支到 Master 分支的 Github Pull Request 显示以前的提交。如何避免此类问题?
- c++ - constexpr 使用 clang 编译 TensorFlow 时出错