Calculating the week in a year, week in a month and quarter from a date

817 views
Skip to first unread message

Constantine Vass

unread,
Aug 30, 2014, 5:42:24 PM8/30/14
to golan...@googlegroups.com
I have a date like this:

Today:
2014-08-30

From which I know 
Year= 2014
Month= 08 - August
Day= 30

I want to know:
1) from 52 weeks in a year, the week number this date occurred
Week=x

2) from 4 weeks in a month, the week number this date occurred
WeekInMonth=08-x
in format - Month-WeekNumberInAMonth

3) from 4 quarters in a year, the quarters this date occurred
Quarter=x

Ho to make this in most effective way?

Rui Ueyama

unread,
Aug 30, 2014, 5:48:32 PM8/30/14
to Constantine Vass, golang-nuts
Which do you count January 5th in the following calendar as, first week or second week of the year? Also, is January 5th is first week or second week in January?
      January               February               March          
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  
          1  2  3  4                     1                     1  
 5  6  7  8  9 10 11   2  3  4  5  6  7  8   2  3  4  5  6  7  8  
12 13 14 15 16 17 18   9 10 11 12 13 14 15   9 10 11 12 13 14 15  
19 20 21 22 23 24 25  16 17 18 19 20 21 22  16 17 18 19 20 21 22  
26 27 28 29 30 31     23 24 25 26 27 28     23 24 25 26 27 28 29  
                                            30 31                 


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Constantine Vass

unread,
Aug 30, 2014, 6:10:46 PM8/30/14
to golan...@googlegroups.com, ths...@gmail.com
Yeas, week in a month does not make sense because the first and last in each month overlap.
Still there a 52 weeks in a year. 

The idea is to represent this information in a chart- a year has 4 Quarters - easily to represent 
in a chart - the number of months in year is divided 3 and we have 4 Quarters - because 1 Quarter is 3 months 

If I want to represent a Month similar way in a chart - yes I can divide by 3 and have 3 divisions by 10 days -
but 10 days do not have a name like Quarter, thus -the week in a month. But it is not correct obviously.

Constantine Vass

unread,
Aug 30, 2014, 6:21:33 PM8/30/14
to golan...@googlegroups.com, ths...@gmail.com
4–4–5 calendar is more appropriate for this case

Sam Fourman Jr.

unread,
Aug 30, 2014, 6:27:38 PM8/30/14
to Constantine Vass, golan...@googlegroups.com
On Sat, Aug 30, 2014 at 5:21 PM, Constantine Vass <ths...@gmail.com> wrote:
4–4–5 calendar is more appropriate for this case


On Saturday, August 30, 2014 3:10:46 PM UTC-7, Constantine Vass wrote:
Yeas, week in a month does not make sense because the first and last in each month overlap.
Still there a 52 weeks in a year. 



package main

import "fmt"
import "time"

func main() {
        year, week := time.Now().ISOWeek()
        fmt.Printf("Year %d\n", year)
        fmt.Printf("Week %d\n", week)

--

Sam Fourman Jr.
Reply all
Reply to author
Forward
0 new messages