'the difference between two date Angular [duplicate]
I have to compare two date in angular to know The number of days enter image description here
Solution 1:[1]
I'd not use a date library in order to do a particular corner case but nowadays people normally use date-fns in order to work with dates.
So if you use that it's really simple basically you can compare dates by doing:
isEqual(date1, date2)
Get days difference between two dates
And so on... the lib has tons of methods to work with days, dates, etc..
Have a look on the links above, you can basically do anything you want with dates in a really simple way. Also, if you gonna work using timezones you can use date-fns-tz.
Solution 2:[2]
this is my code
enter code here
onBlurEvent(event: any){
console.log(event.target.value);
this.date_debut = event.target.value;
console.log("date_debut",this.date_debut)
}
onEvent(event: any){
console.log(event.target.value);
this.date_fin = event.target.value;
console.log("date_fin",this.date_fin)
}
calculateDiff(date1:any,date2:any) {
var date1 = this.date_debut;
var date2 = this.date_fin;
var diffDays:any = Math.floor((date2 - date1) / (1000 * 60 * 60 * 24));
console.log("diffDays",diffDays)
return diffDays;
}
Solution 3:[3]
Use the MouseEnter event to capture the mouse cursor hovering over the button borders,
and the MouseLeave event to detect when the cursor leaves the button borders, in order to return it to its original size.
Here is one way to implement such functionality:
private Size OriginalButtonSize;
private Size HoveredSize;
private void Form1_Load(object sender, EventArgs e)
{
OriginalButtonSize = this.button1.Size;
HoveredSize = new Size(OriginalButtonSize.Width + 30, OriginalButtonSize.Height + 30);
}
private void button1_MouseEnter(object sender, EventArgs e)
{
button1.Size = HoveredSize;
}
private void button1_MouseLeave(object sender, EventArgs e)
{
button1.Size = OriginalButtonSize;
}
Output:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | saadouna |
| Solution 3 | Jonathan Applebaum |

