当前位置:网站首页>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?
- Dynamic memory allocation (malloc calloc realloc free)
- LxC terminal login method
- 情感计算与理解研究发展概述
- "New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
- [shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
- Attack and defense world PWN question: Echo
- Market Research - current market situation and future development trend of handheld wound imaging equipment
- [C question set] of V
- From personal heroes to versatile developers, the era of programmer 3.0 is coming
猜你喜欢

图像基础概念与YUV/RGB深入理解

Introduction to the principle of geographical detector

Daily book - low code you must understand in the era of digital transformation
![[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)](/img/f7/cb41d159e5c5ef3f4f1b9468d52ccc.jpg)
[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)

From "bronze" to "King", there are three secrets of enterprise digitalization

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

Micro service gateway selection, please accept my knees!

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

Dynamic memory allocation (malloc calloc realloc free)

About test cases
随机推荐
[shutter] shutter resource file use (import resource pictures | use image resources)
TinyMCE visual editor adds Baidu map plug-in
Utilisation de simpletk - 4. Question étrange
C language, to achieve three chess games
Web side defense Guide
Kubernetes resource object introduction and common commands (4)
It's not easy to say I love you | use the minimum web API to upload files (swagger support) # yyds dry inventory #
Market Research - current market situation and future development trend of genome editing mutation detection kit
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
Market Research - current market situation and future development trend of total nutrition products
Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
[QT] QT multithreading development - four methods to realize multithreading design
[sword finger offer] 56 - I. the number of numbers in the array
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
100 important knowledge points that SQL must master: using cursors
开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...
20220702 how do programmers build knowledge systems?
sql service 截取字符串
关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
【微服务|Sentinel】重写sentinel的接口BlockExceptionHandler