Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: Reliable way to obtain start, end days of a month #31142

mcandre opened this Issue Mar 29, 2019 · 2 comments


None yet
4 participants
Copy link

commented Mar 29, 2019

Hey, I noticed that the stdlib time package does not offer direct, reliable methods for obtaining the start and end days of a timestamp's month. There are a number of Stack Overflow suggestions, as well as a (reportedly inaccurate) third party package for this.

Would be good to have a standard method to call for this common use case, rather than relying on the community to get complex date and time rules right.

@dmitshur dmitshur changed the title Reliable way to obtain start, end days of a month time: Reliable way to obtain start, end days of a month Mar 29, 2019


This comment has been minimized.

Copy link

commented Mar 29, 2019

The first day of a month seems straightforward:

    monthStart := time.Date(d.Year(), d.Month(), 1, 0, 0, 0, 0, d.Location())

and the last day of the month is only slightly more complicated:

    monthEnd := time.Date(d.Year(), d.Month() + 1, 0, 0, 0, 0, 0, d.Location())

This comment has been minimized.

Copy link

commented Apr 2, 2019

@mcandre - Does this suffice your needs or you would still prefer to have a helper for this ? IMO, this method just leverages the standard date normalization behavior and lets users get their desired output.

If you would like this to be added in standard library, some usages of this in the real world will be helpful for us to make a decision. We would need to understand why such a helper needs to be in the standard library and not exist as a third party package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.