如何从年龄,月份和日期计算出生日期 [英] How to calculate the date of birth from age years, months and days

查看:88
本文介绍了如何从年龄,月份和日期计算出生日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class="col-md-12" *ngIf="!DOBKnown">
<div class="col-md-6">
<div class="form-group">
<label class="col-sm-3 control-label mandatory">Approx. Age</label>
<div class="col-sm-3">
<input type="text" name='years' class="form-control" placeholder="Years" maxlength="3" (keyup)="checkYear($event.target.value)" formControlName="ageYears">
</div>
<div class="col-sm-3">
<input type="text"  name='months' class="form-control" placeholder="Months" (keyup)="checkMonth($event.target.value)" formControlName="ageMonths">
</div>
<div class="col-sm-3"> 
<input type="text"  name='days' class="form-control" placeholder="Days" (keyup)="checkDay($event.target.value)" formControlName="ageDays">
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <div class="form-group">
                                                                <label class="col-sm-3 control-label"> Approx. Date Of Birth </label>
                                                                <div class="col-sm-9">
                                                                    <input type="date" class="form-control" (keyup)="calculate()" formControlName="dateOfBirth" [(ngModel)]="dobYear" disabled>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>



createPatient() {
        this.createPatientForm = new FormGroup({
            firstName: new FormControl('', <any>Validators.required),
            lastName: new FormControl('', <any>Validators.required),
            dateOfBirth: new FormControl('', <any>Validators.required),
            ageYears: new FormControl('', <any>Validators.required),
            ageMonths: new FormControl('', <any>Validators.required),
            ageDays: new FormControl('', <any>Validators.required),

        });
    }
**Patient create form**





我尝试过:





What I have tried:

checkYear(year){
    let mon = year.substring(0,(year.length-1));
    if(year.length>0 && year.length<7){
		if(year == 0){
            year=mon;
		}
		else if(year < 1 || year>150){
            year='';
		}
	}
	else if(year.length>4){
        year=mon;
	}
}


I tried to check the year.But I dint understand how to calculate month and day.If it is less than the current month and day.How will I give.

推荐答案

event.target.value)formControlName =ageYears>
< / div>
< div class =col-sm-3>
< input type =textname ='months'class =form-controlplaceholder =Months (keyup)=checkMonth(
event.target.value)" formControlName="ageYears"> </div> <div class="col-sm-3"> <input type="text" name='months' class="form-control" placeholder="Months" (keyup)="checkMonth(


event.target.value)formControlName =ageMonths>
< / div>
< div class = col-sm-3>
< input type =textname ='days'class =form-controlplaceholder =Days(keyup)=checkDay(
event.target.value)" formControlName="ageMonths"> </div> <div class="col-sm-3"> <input type="text" name='days' class="form-control" placeholder="Days" (keyup)="checkDay(


event.target.value)formControlName =ageDays>
< / div>
< / div>
< / div>
< div class =col-md-6>
< div class =form-group>
< label class =col-sm-3 control-label>约。出生日期< / label>
< div class =col-sm-9>
< input type =dateclass =form-control(keyup)=calculate()formControlName =dateOfBirth[(ngModel)] =dobYear已禁用>
< / div>
< / div>
< / div>
< / div>



createPatient(){
this.createPatientForm = new FormGroup({
firstName:new FormControl('',< any> Validators。必填),
lastName:new FormControl('',< any> Validators.required),
dateOfBirth:new FormControl('',< any> Validators.required),
ageYears :new FormControl('',< any> Validators.required),
ageMonths:new FormControl('',< any> Validators.required),
ageDays:new FormControl('',< ;任何> Validators.required),

});
}
**患者创建表格**
event.target.value)" formControlName="ageDays"> </div> </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="col-sm-3 control-label"> Approx. Date Of Birth </label> <div class="col-sm-9"> <input type="date" class="form-control" (keyup)="calculate()" formControlName="dateOfBirth" [(ngModel)]="dobYear" disabled> </div> </div> </div> </div> createPatient() { this.createPatientForm = new FormGroup({ firstName: new FormControl('', <any>Validators.required), lastName: new FormControl('', <any>Validators.required), dateOfBirth: new FormControl('', <any>Validators.required), ageYears: new FormControl('', <any>Validators.required), ageMonths: new FormControl('', <any>Validators.required), ageDays: new FormControl('', <any>Validators.required), }); } **Patient create form**





我尝试过:





What I have tried:

checkYear(year){
    let mon = year.substring(0,(year.length-1));
    if(year.length>0 && year.length<7){
		if(year == 0){
            year=mon;
		}
		else if(year < 1 || year>150){
            year='';
		}
	}
	else if(year.length>4){
        year=mon;
	}
}


I tried to check the year.But I dint understand how to calculate month and day.If it is less than the current month and day.How will I give.


这篇关于如何从年龄,月份和日期计算出生日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆