Figuring out first day of a month

  • Thread starter MrGillig
  • Start date
In summary, the conversation discusses the possibility of calculating the first day of the month based on the date and the corresponding number for each day of the week. One person suggests a formula to determine the weekday of the first day of the month and clarifies that the days of the week should be counted starting from 0, with Sunday being 0 and Saturday being 6. They also mention the need to add 7 if the result is below 0.
  • #1
MrGillig
4
0
Hey guys!

Say I have a date. Let's just take todays date 05/04/2009.

And say I have numbers 0 - 6 corresponding to each day of the week ie. Sunday is 0, Monday is 1 etc.

From just knowing the day of the date, in this case 5, and that today is a Sunday, is it possible to calculate what the first day of the month was? By using the numbers that correspond to each day, of course.

So, I'll reiterate: from just knowing that its the 5th and that it's a Sunday (0), is it possible to figure out what the first day of the month was?
 
Mathematics news on Phys.org
  • #2
Let today be the dth day of the month, and the day of the week be w. The weekday of the first day of the month is the least residue of [tex]w-(d-1)[/tex] mod 7 and in general, the weekday of the kth day is the least residue of [tex]w-(d-k)[/tex] mod 7.
 
  • #3
I'm confused. If I were to plug the values in for today would they then be "0 - (5+1) % 7". When I calculate this I seem to get -6, which isn't Wednesday. Did I mess up the calculation somewhere?

EDIT: Just read your edit sorry. Gonna try again.
 
  • #4
Sorry man but I'm still confused. If I plug in the values for today, for instance, I get -4. Should I be counting from 1 instead of 0 for the days of the week ie. Sunday is 1, Monday is 2 etc?
 
  • #5
MrGillig said:
Sorry man but I'm still confused. If I plug in the values for today, for instance, I get -4. Should I be counting from 1 instead of 0 for the days of the week ie. Sunday is 1, Monday is 2 etc?

-4 = 3 (mod 7).
 
  • #6
Ah I realize now how to equate it to correspond to the day of the week. If it happens to be below 0, I add 7 and get the result for the number corresponding to the first day of the month.

Thanks for the help!
 

1. How do I determine the first day of the month?

To determine the first day of the month, you can use a date object in your programming language of choice and specify the month and year. Then, you can use the getDay() method to retrieve the day of the week, with 0 representing Sunday, 1 representing Monday, and so on.

2. Can I use a formula to calculate the first day of the month?

Yes, you can use a formula to calculate the first day of the month. One way to do this is by using the Zeller's congruence formula, which takes into account the year, month, and date to determine the day of the week. However, this formula may not be as accurate for dates before the 19th century.

3. How can I determine the first day of the month in different time zones?

The first day of the month will vary depending on the time zone. To determine the first day of the month in a specific time zone, you can use a date and time library that allows you to specify the time zone in your code. This will ensure that the date and time are adjusted accordingly for the specific time zone.

4. What are some common errors when figuring out the first day of the month?

Common errors when figuring out the first day of the month include forgetting to account for leap years, using the wrong date format, and not considering the time zone. It is important to carefully consider all factors that may affect the date, such as daylight saving time and different calendar systems.

5. Can I determine the first day of the month without using a computer program?

Yes, you can determine the first day of the month without using a computer program. You can use a calendar or a printed table that shows the first day of the month for different years. Alternatively, you can use a formula or a date calculation tool available online to calculate the first day of the month manually.

Similar threads

Replies
2
Views
11K
Replies
1
Views
977
  • Precalculus Mathematics Homework Help
Replies
18
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
969
Replies
3
Views
946
Replies
2
Views
303
Replies
2
Views
3K
Replies
5
Views
2K
Replies
2
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
3
Views
2K
Back
Top