当前位置:网站首页>php实现根据输入的年龄查询出生日期符合的数据
php实现根据输入的年龄查询出生日期符合的数据
2022-07-02 22:01:00 【if时光重来】
需求描述: 前端发送请求如33-55岁,后端拿到年龄数据后将指定年龄转为日期
$search = $_POST;
$year = date('Y');
$month = date('m');
$day = date('d');
$max_birth = '';
$min_birth = '';
// 用户输入了最小年龄和最大年龄
if(isset($search['person_age_min']) && isset($search['person_age_max'])){
$min = min($search['person_age_min'], $search['person_age_max']);
$max = max($search['person_age_min'], $search['person_age_max']);
# 计算最大年龄的最早出生日期
$max_year = $year - $max - 1;
$max_birth = date('Y-m-d', strtotime("+1 day", strtotime($max_year.'-'.$month.'-'.$day)));
# 计算最小年龄的最后出生日期
$min_year = $year-$min;
$min_birth = $min_year.'-'.$month.'-'.$day;
}elseif(isset($search['person_age_min']) && !isset($search['person_age_max'])){ //用户只输入了最小年龄
# 计算最大年龄的最早出生日期
$max_year = $year - $search['person_age_min'] - 1;
$max_birth = date('Y-m-d', strtotime("+1 day", strtotime($max_year.'-'.$month.'-'.$day)));
# 计算最小年龄的最后出生日期
$min_year = $year-$search['person_age_min'];
$min_birth = $min_year.'-'.$month.'-'.$day;
}elseif(!isset($search['person_age_min']) && isset($search['person_age_max'])) { // 用户只输入了最大年龄
# 计算最大年龄的最早出生日期
$max_year = $year - $search['person_age_max'] - 1;
$max_birth = date('Y-m-d', strtotime("+1 day", strtotime($max_year.'-'.$month.'-'.$day)));
# 计算最小年龄的最后出生日期
$min_year = $year-$search['person_age_min'];
$min_birth = $min_year.'-'.$month.'-'.$day;
}
if(!empty($min_birth) && !empty($max_birth)){
// sql语句
$sql = "select * from user where birth between $max_birth and $min_birth";
}
边栏推荐
- ServiceMesh主要解决的三大痛點
- [QT] QT multithreading development - four methods to realize multithreading design
- Bridge emqx cloud data to AWS IOT through the public network
- [staff] Sibelius 7.5.1 score software installation (software download | software installation)
- C语言,实现三子棋小游戏
- 使用 EMQX Cloud 实现物联网设备一机一密验证
- 《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
- #include errors detected. Please update your includePath.
- Leetcode circular linked list (fast and slow pointer) code line by line interpretation
- ArrayList analysis 2: pits in ITR, listiterator, and sublist
猜你喜欢

TinyMCE visual editor adds Baidu map plug-in

SimpleITK使用——4. 奇怪的問題

开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...

#include errors detected. Please update your includePath.

LightGBM原理及天文数据中的应用

Sql service intercepts string
![[shutter] shutter gesture interaction (small ball following the movement of fingers)](/img/5a/a8dad8a0943645c980cc4fe7cb55d4.gif)
[shutter] shutter gesture interaction (small ball following the movement of fingers)

【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)

The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
![[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)](/img/27/8594ba0b49d5008b7469967babed17.jpg)
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
随机推荐
APP页面分享口令Rails实现
Task and privilege level protection
Market Research - current market situation and future development trend of aircraft front wheel steering system
Market Research - current market situation and future development trend of aircraft wireless intercom system
Sql service intercepts string
分享一下如何制作专业的手绘电子地图
:last-child 不生效解决
Learn computer knowledge from scratch
Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning
scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
Socket socket c/s end process
Perceptron model and Application
Unity3D学习笔记4——创建Mesh高级接口
Unity发布WebGL播放声音的一种方法
How to center the positioned text horizontally and vertically
[Jianzhi offer] 57 And are two numbers of S
What "real skills" should a million year old cloud native developer master? Alibaba, Tencent, meituan and byte decrypt together
UE4 UI自适应屏幕
服务可见可观测性
The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink