Best answer

Does this date format feature exist

  • 1 December 2022
  • 9 replies
  • 149 views

Userlevel 1
Badge

Hey, I would like to know if this feature exists.

 

Is there any date formatting feature that shows if an input date is first week of the month or second week of the month or third week of the month or 4th week of the.

 

For example, if the input data is November 2nd 2022, then I would like Zapier to tell me that this is the 1st week of the month.

 

Does something like this exist?

icon

Best answer by GetUWired 1 December 2022, 19:59

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

9 replies

Userlevel 7
Badge +14

Hi @Fahad.S 

Good question.

No, that does not exist, and that logic would likely have to be configured in a custom Code step: https://zapier.com/apps/code/help

Also, it depends on how you consider weeks to be calculated. (e.g. starting on Monday, starting on Sunday, starting on some other day, the first week that has 4+ days in the month, etc.)

 

For example, if the input data is November 2nd 2022, then I would like Zapier to tell me that this is the second week of the month.

How would November 2, 2022 be in the second week of the month?

Userlevel 1
Badge

Also, it depends on how you consider weeks to be calculated. (e.g. starting on Monday, starting on Sunday, starting on some other day, the first week that has 4+ days in the month, etc.)

I would like the week to start with Monday, how would the code look like for this.

How would November 2, 2022 be in the second week of the month?

Ah, my bad lol, I meant to write 1st week of the month

 

Userlevel 7
Badge +14

@Fahad.S 

I have not yet written that type of custom Code.

Perhaps try some GSearches or consider hiring a Zapier Expert: https://zapier.com/experts

Userlevel 1
Badge

@Fahad.S

I have not yet written that type of custom Code.

Perhaps try some GSearches or consider hiring a Zapier Expert: https://zapier.com/experts

Thanks for letting me know, I found a code on stack overflow but not sure how to implement into Zapier, what do you think.

code I found

def week_of_month(dt):
""" Returns the week of the month for the specified date.
"""

first_day = dt.replace(day=1)

dom = dt.day
adjusted_dom = dom + first_day.weekday()

return int(ceil(adjusted_dom/7.0))

 

 

Userlevel 7
Badge +12

As @Troy Tessalone mentioned, this really will depend on how you want to determine what week you are in.. If you just assume that the 1st of every month is the 1st of the week for that month then the math is fairly straightforward. You would just round up the day of the month divided by 7

i.e November 2: 2/7 = .286 so rounded up is week 1. 
November 15th: 15/7 = 2.143 so rounded up is week 3

with this method you will end up with up to 5 weeks for most months. 

Userlevel 1
Badge

If you just assume that the 1st of every month is the 1st of the week for that month then the math is fairly straightforward. You would just round up the day of the month divided by 7

Suppose I assume 1st of every month is the first week of the month, what should I do what should I do to make this happen in Zapier

Userlevel 7
Badge +12

You can do this with a code step or 2 formatter steps. 

Formatter Steps:

1st a date time formatter step to return the date. Inputs shown below are a sample your date input might be different than just the current time the zap is running and you might also not be in eastern time. This will give you back just the day portion of the month. 


The second step would be a numbers formatter

 

Userlevel 1
Badge

You can do this with a code step or 2 formatter steps. 

Formatter Steps:

1st a date time formatter step to return the date. Inputs shown below are a sample your date input might be different than just the current time the zap is running and you might also not be in eastern time. This will give you back just the day portion of the month. 


The second step would be a numbers formatter

 

thanks, will try it out

Userlevel 7
Badge +9

@Fahad.S How are things going here? Were you able to configure those Formatter steps and get the result you’re looking for? Let us know - we want to make sure you’re good to go here!