Jump to content

Text expansion snippet to find Monday's date of the current week?


Recommended Posts

I title a lot of files by including the start date of that week

  • e.g. Ops Update - Week of 1/22/24

 

Is there a way to create an Alfred snippet to automatically determine the Monday of that week?

 

In Excel it would be something like this:

 

=IF(WEEKDAY(TODAY(),2)<=5,TODAY()-WEEKDAY(TODAY(),2)+1,TODAY()-WEEKDAY(TODAY(),2)+8)

 

 

Link to comment

I think you're going to have to do some work to achieve that. However, this AppleScript should be a good place to start:

set theDate to the current date
repeat until (theDate's weekday) = Monday
	set theDate to theDate - 1 * days
end repeat
set theDate to short date string of (theDate)
my formatDate(theDate)

on formatDate(theDateStr)
	set {dd, mm, yyyy} to words of (short date string of (date theDateStr))
	set formattedDate to (mm & "/" & dd & "/" & yyyy)
	return formattedDate
end formatDate

It will take today's date, calculate the date of the Monday immediately preceding it and return that date in US format. It's not exactly what you want but you may be able to build on it.

 

Stephen

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...