You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Convert date to a week number

Currently I use user input to work this out.


like this


display dialog thePrefix & "Please enter the week number:" default answer theWeekNumber

set theWeekNumber to text returned of result

display dialog thePrefix & "Please enter the Month:" default answer theMonth

set theMonth to text returned of result



For the month line I need it to convert say the month we are in to "08 August" I like to use the "08" as it helps keep the order in list view consistant.


Now for the week number it is more complicated as I need it to work with our work calender.


I use a similare method in excel the calulation takes this form.


=INT(((NOW())-DATE(YEAR((NOW())-31),-3,-14)-WEEKDAY((NOW()),1))/7)+2



Monday August 20th will be week1.


How can i get applescript to get the date and convert to week number and also the month.


Many Thanks


Matt

iMac, Mac OS X (10.6.8)

Posted on Aug 1, 2012 3:22 AM

Reply
19 replies

Aug 2, 2012 6:13 AM in response to MattJayC

MattJayC wrote:



I did wonder if a few irregularites like that might happen.


I just did a run through and the result was 51 (I was expecting 50)


But it is right the 3rd Monday of August (sunday to be precise but never in on Sunday so difference) Can't quite work out where I need to make the alteration.


Also is "augustThirdWeek" my value that i can then use within a script? i.e. augustThirdWeek = 51


Thanks


Matt


For me it's okay, I get the same value with your Excel formula.


So here is a table, the first week begins at Monday, August 15, 2011

The first week of the next year is Monday, August 20, 2012


Week 01 = Mon 08/15/2011

Week 02 = Mon 08/22/2011

Week 03 = Mon 08/29/2011

Week 04 = Mon 09/05/2011

Week 05 = Mon 09/12/2011

Week 06 = Mon 09/19/2011

Week 07 = Mon 09/26/2011

Week 08 = Mon 10/03/2011

Week 09 = Mon 10/10/2011

Week 10 = Mon 10/17/2011

Week 11 = Mon 10/24/2011

Week 12 = Mon 10/31/2011

Week 13 = Mon 11/07/2011

Week 14 = Mon 11/14/2011

Week 15 = Mon 11/21/2011

Week 16 = Mon 11/28/2011

Week 17 = Mon 12/05/2011

Week 18 = Mon 12/12/2011

Week 19 = Mon 12/19/2011

Week 20 = Mon 12/26/2011

Week 21 = Mon 01/02/2012

Week 22 = Mon 01/09/2012

Week 23 = Mon 01/16/2012

Week 24 = Mon 01/23/2012

Week 25 = Mon 01/30/2012

Week 26 = Mon 02/06/2012

Week 27 = Mon 02/13/2012

Week 28 = Mon 02/20/2012

Week 29 = Mon 02/27/2012

Week 30 = Mon 03/05/2012

Week 31 = Mon 03/12/2012

Week 32 = Mon 03/19/2012

Week 33 = Mon 03/26/2012

Week 34 = Mon 04/02/2012

Week 35 = Mon 04/09/2012

Week 36 = Mon 04/16/2012

Week 37 = Mon 04/23/2012

Week 38 = Mon 04/30/2012

Week 39 = Mon 05/07/2012

Week 40 = Mon 05/14/2012

Week 41 = Mon 05/21/2012

Week 42 = Mon 05/28/2012

Week 43 = Mon 06/04/2012

Week 44 = Mon 06/11/2012

Week 45 = Mon 06/18/2012

Week 46 = Mon 06/25/2012

Week 47 = Mon 07/02/2012

Week 48 = Mon 07/09/2012

Week 49 = Mon 07/16/2012

Week 50 = Mon 07/23/2012

Week 51 = Mon 07/30/2012

Week 52 = Mon 08/06/2012

Week 53 = Mon 08/13/2012

Week 01 = Mon 08/20/2012

Aug 2, 2012 8:12 AM in response to MattJayC

Hi,


It's impossible to script something that is not logical.

Because the logic is the number of weeks between these dates (Monday, August 15, 2011 and Monday, August 20, 2012).



But you can do it manually :

add this line in your script : set weekNumber to weekNumber -1 and removes it on Monday, August 20, 2012



--

Any ways, I tested my script up to the year 2032, it will happen four times.


Week 01 = Monday, August 15, 2011

Week 53 = Mon 08/13/2012


Week 01 = Mon 08/15/2016

Week 53 = Mon 08/14/2017


Week 01 = Mon 08/15/2022

Week 53 = Mon 08/14/2023


Week 01 = Mon 08/16/2027

Week 53 = Mon 08/14/2028

Aug 2, 2012 8:51 AM in response to Jacques Rioux

I just thought of something, it's possible some way ;

The script check the number of weeks in a year, If number of weeks in a year = 53 :

-- So we need to know at what week :


-- At begiining of the year, the first week will be zero , the second week will be 1, not very logical compared to others years that starts at 1.

-- I think the best would be to subtract 1 from the first full week of January or the last week of December.

-- In this case you will have two weeks with the same number.


Tell me what you prefer.

Convert date to a week number

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.