Hướng dẫn dùng glidedate JavaScript
Given dates in the format YYYY-MM-DD, you can use the Date constructor, subtract one from the other and divide by the number of milliseconds in one day. The strings will be parsed as UTC, so there are no issues with daylight saving and ECMAScript has exactly 8.64e7 ms per day. Even if you need to round, daylight saving doesn't change the value by more than 1 hour (and in some places less) so rounding is fine. E.g.
It's generally recommended to avoid the built–in parser, however in this case it's likely OK. But for confidence, parse the strings manually, a library can help but it only requires a 2 line function. If your dates are not created as above and are not set to midnight, you can get days between dates by setting them to midnight, subtracting and rounding, e.g.
|