Click here to Skip to main content
15,946,988 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to set future date as default date in angular,as of now I am getting today's date but I need to get 30 days ahead which has to be set as default date value

What I have tried:

date1 = new Date();
currentYear = this.date1.getfullYear();
CurrentMonth = this.date1.getMonth();
currentDay = this.date1.getDate();

Today date = "";
FinalMonth : any;
FinalDay : any= this.currentDay +30;

ngOnInit(): void{
if(this.finalDay>30 && this.FinalDay<=61){
this.FinalDay = this.FinalDay -30;
}
else{
this.FinalDay = this.currentDay;
}
if(this.currentMonth<=11){
this.FinalMonth= this.currentMonth +1;
}
if(this.currentMonth==12){
this.FinalMonth=1;
this.currentYear=this.currentYear +1;
}
this.FinalDate = this.currentyear+"-"+ this.FinalMonth+"-"+this.FinalDay;
Posted
Updated 22-Dec-22 1:05am
v2
Comments
Richard Deeming 22-Dec-22 6:45am    
How? By writing some code to do it.

Since you've provided zero details of your code, nor any details of what you have tried or where you are stuck, nobody can help you.

Click the green "Improve question" link and update your question to include a clear and complete description of what you are trying to do, the relevant parts of your code, and the full details of any errors.
[no name] 26-Dec-22 10:54am    
https://bobbyhadz.com/blog/typescript-date-add-days

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900