当前位置:网站首页>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";
}
边栏推荐
- 20220702 how do programmers build knowledge systems?
- Ransack组合条件搜索实现
- Promise optimized callback hell
- 《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!
- Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
- scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
- ArrayList analysis 2: pits in ITR, listiterator, and sublist
- Hanoi Tower problem
- Market Research - current situation and future development trend of anti-counterfeiting label market
- [QT] Q multithreaded development - Analysis of multithreaded application examples (Mandelbrot)
猜你喜欢

The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"

20220702 how do programmers build knowledge systems?

情感计算与理解研究发展概述

Interpretation of CVPR paper | generation of high fidelity fashion models with weak supervision
![[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)
![[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)](/img/07/6f2dfb543cb0ab4f27169da7e6ad07.jpg)
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)

Introduction to victoriametrics

An overview of the development of affective computing and understanding research

Ransack组合条件搜索实现

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
随机推荐
Daily book CSO advanced road first exposed
Market Research - current market situation and future development trend of total nutrition products
服务可见可观测性
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
From personal heroes to versatile developers, the era of programmer 3.0 is coming
Commodity information management system (C language document version)
【leetcode】1380. Lucky number in matrix
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
Hanoi Tower problem
UE4 UI自适应屏幕
C language, to achieve three chess games
scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
About test cases
【C 题集】of Ⅴ
From "bronze" to "King", there are three secrets of enterprise digitalization
An overview of the development of affective computing and understanding research
LightGBM原理及天文数据中的应用
Market Research - current market situation and future development trend of aircraft front wheel steering system
《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!
Etcd raft protocol