# MSSQL ENDOFMONTH Replacement

**URL:** <https://community.cdata.com/t/mssql-endofmonth-replacement/855>\
**Category:** CData Virtuality \[Archived\]\
**Tags:** article, cdata-virtuality\
**Created:** [July 12, 2024, 5:26pm UTC](https://community.cdata.com/t/mssql-endofmonth-replacement/855 "2024-07-12T17:26:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@anonymous](https://community.cdata.com/u/anonymous)\
**Post date:** [July 12, 2024, 5:26pm UTC](https://community.cdata.com/t/mssql-endofmonth-replacement/855/1 "2024-07-12T17:26:49Z")

</div>

Workaround procedure for [ENDOFMONTH-Funktion (DAX) - DAX | Microsoft Learn](http://technet.microsoft.com/de-de/library/ee634239.aspx)

> `CREATE VIRTUAL PROCEDURE views.endofmonth( IN getdate date ) returns (outdate date) asBEGIN     DECLARE date monthlater =  timestampadd( SQL_TSI_MONTH, 1, getdate );    select  timestampadd( SQL_TSI_DAY, - dayofmonth(monthlater), monthlater); END;;`

### &nbsp;

### **Usage Examples**

> `call views.endofmonth( cast ( '2012-02-07' as date ) ) result: 2012-02-29 call endofmonth( current_date ) result: Last day of current month using in WHERE clause SELECT foo from table.bar WHERE column = ( call endofmonth( current_date ) )`
