Skip to content
+1-888-319-3663

COMMUNITY FORUM

Getting the first and last date of the month using a script

Arthur asked 2 years ago
Hi,
Can someone share a script to get the first and last date from a date column in a datasource?
I have tried but I can’t seem to get the format right.
Cheers
 
Answers
Patrick Roth Staff answered 2 years ago
Arthur,
I’d do something like this:
https://stackoverflow.com/questions/3720785/get-the-last-en-for-last-day-of-a-month
This one uses the “current year/month” and yours is from your data.  But you’d then just use _MYDATE.Year and _MYDATE.Month instead and it should come out the same.
Arthur Achilleos replied 2 years ago

I used the following for anyone else who wants to do this:

‘First Date
Dim sourcedate as Datetime

sourcedate = DateTime.Now.ToShortDateString() ‘replace with date field from datasource

Return New DateTime(sourceDate.Year, sourceDate.Month, 1)

‘Last Day
Dim sourcedate as Datetime

sourcedate = DateTime.Now.ToShortDateString() ‘replace with date field from datasource

Dim lastDay As DateTime = New DateTime(sourceDate.Year, sourceDate.Month, 1)

Return lastDay.AddMonths(1).AddDays(-1) ‘change addmonths accordingly


If you would like to submit an answer or comment, please sign in to the eOne portal.