当前位置:网站首页>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";
}
边栏推荐
- 开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...
- Simpleitk use - 3 Common operations
- [QT] QT multithreading development - four methods to realize multithreading design
- Service visibility and observability
- Promise optimized callback hell
- 20220702-程序员如何构建知识体系?
- Infrastructure is code: a change is coming
- Commodity information management system (C language document version)
- What is it that makes you tremble? Those without fans can learn
- UE4 UI自适应屏幕
猜你喜欢
Reading experience of just because
《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!
Kubernetes resource object introduction and common commands (4)
Promise optimized callback hell
基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
[shutter] shutter application theme (themedata | dynamic modification theme)
Daily book -- analyze the pain points of software automation from simple to deep
How to write a good program when a big book speaks every day?
C语言,实现三子棋小游戏
20220702 how do programmers build knowledge systems?
随机推荐
Market Research - current market situation and future development trend of aircraft audio control panel system
Utilisation de simpletk - 4. Question étrange
Daily book CSO advanced road first exposed
Market Research - current market situation and future development trend of third-party data platform
Unity3d learning notes 4 - create mesh advanced interface
App page sharing password rails implementation
How to center the positioned text horizontally and vertically
关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
Market Research - current market situation and future development trend of aircraft wireless intercom system
sql service 截取字符串
Market Research - current market situation and future development trend of handheld wound imaging equipment
The difference between include < > and include ""
Landingsite eband B1 smoke test case
图像基础概念与YUV/RGB深入理解
ArrayList analysis 2: pits in ITR, listiterator, and sublist
Pointer and string
Introduction to victoriametrics
Simpleitk use - 4 Strange question
Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
Task and privilege level protection