# Rename with last day of month when source only contains year-month

**URL:** https://discourse.devontechnologies.com/t/rename-with-last-day-of-month-when-source-only-contains-year-month/68175
**Category:** Automation
**Tags:** devonthink3, automation
**Created:** [December 5, 2021, 8:06pm UTC](https://discourse.devontechnologies.com/t/rename-with-last-day-of-month-when-source-only-contains-year-month/68175 "2021-12-05T20:06:36Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![DTLow](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/dtlow/32/18161_2.png) [@DTLow](https://discourse.devontechnologies.com/u/DTLow)
#### Post date: [December 6, 2021, 12:11am UTC](https://discourse.devontechnologies.com/t/rename-with-last-day-of-month-when-source-only-contains-year-month/68175/5 "2021-12-06T00:11:30Z")

</div>

The record is passed to the script  
See the skeleton script below

```auto
on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
                                           <<< insert code
		end repeat
	end tell
end performSmartRule

```

> I’d like to rename it to has the last day of that month

Here’s example code to get the last day of the month and rename the record

```auto
			set theName to name of theRecord
			set theName to theName & my LastDay(texts -6 thru -1 of theName)
			set name of theRecord to theName

on LastDay(theDate)
	set theyyyy to characters 1 thru 4 of theDate as string
	set themm to characters 5 thru 6 of theDate as string
	-- Convert to the first day of the following month
	-- Then get the previous day
	set NewDate to current date
	set year of NewDate to theyyyy
	set day of NewDate to 1
	set month of NewDate to (themm as integer) + 1
	set NewDate to NewDate - (1 * days)
	return day of NewDate
end LastDay

```

---

_[View the full topic](https://discourse.devontechnologies.com/t/rename-with-last-day-of-month-when-source-only-contains-year-month/68175)._
