The monthend(number_date)
function expects a number (date) as the argument. But in your example, you're giving it a text date.
monthend("2023-07-01") // returns error
Text dates are not real dates for EasyMorph, because in EasyMorph, like in Excel, dates are numbers. See this tutorial article: EasyMorph | Type system and expressions
A date literal (e.g. #2023-07-01) is also effectively a number (in this case 45108). A date literal is just a more convenient way to specify a date, because it is immediately clear that #2023-07-01 is July 1st, 2023. While it's not obvious that number 45108 is also July 1st, 2023 (because there are 45108 days between July 1st, 2023 and Jan 1st, 1900). The pound sign can't be used for anything else except specifying date constants explicitly. It's not a function or an operator. It's a syntax for date literals (constants).
Therefore, in order to use monthend() you need to convert text "2023-07-01" into a number date. You can do this with the date() function. So the expression below works:
monthend(date("2023-07-01", "yyyy-MM-dd")) // returns 45138
Finally, if you want to convert the number date 45138 into a text date, the use the format() function, which is the opposite of the date() function:
format(monthend(date("2023-07-01", "yyyy-MM-dd")), "yyyy-MM-dd") // returns text value "2023-07-31"
Here is your project updated:
monthend_error_001.morph (3.6 KB)
To avoid unnecessary conversions, perform all operations with dates as numbers, and only convert them into text dates when no other operations should be done.
EasyMorph helps see numbers as dates by offering a date format for numbers in a column:
This format only affects how numbers are displayed in the datagrid. They do not modify the numeric values themselves.
So to work conveniently with dates:
- Convert text dates into number dates
- Set column formatting to a date format to see dates instead of numbers in columns with dates